<commit_before>/* Copyright (c) 2006-2007 MetaCarta, Inc., published under a modified BSD license.
 * See http://svn.openlayers.org/trunk/openlayers/repository-license.txt 
 * for the full text of the license. */

/**
 * Header: OpenLayers Base Types
 * Modifications to standard JavaScript types are described here.
 */

/*********************
 *                   *
 *      STRING       * 
 *                   * 
 *********************/


/**
 * APIMethod: String.startsWith
 * Whether or not a string starts with another string. 
 * 
 * Parameters:
 * sStart - {Sring} The string we're testing for.
 *  
 * Return:
 * {Boolean} Whether or not this string starts with the string passed in.
 */
String.prototype.startsWith = function(sStart) {
    return (this.substr(0,sStart.length) == sStart);
};

/**
 * APIMethod: String.contains
 * Whether or not a string contains another string.
 * 
 * Parameters:
 * str - {String} The string that we're testing for.
 * 
 * Return:
 * {Boolean} Whether or not this string contains with the string passed in.
 */
String.prototype.contains = function(str) {
    return (this.indexOf(str) != -1);
};

/**
 * APIMethod: String.trim
 * Removes leading and trailing whitespace characters from a string.
 * 
 * Return:
 * {String} A trimmed version of the string - all leading and 
 *          trailing spaces removed
 */
String.prototype.trim = function() {
    
    var b = 0;
    while(this.substr(b,1) == " ") {
        b++;
    }
    
    var e = this.length - 1;
    while(this.substr(e,1) == " ") {
        e--;
    }
    
    return this.substring(b, e+1);
};

/**
 * APIMethod: String.indexOf
 * Index of a character in a string.
 * 
 * Parameters:
 * object - {Object} Can be a string or a number
 * 
 * Return: 
 * {Integer} The index of the encountered object, or -1 if not found.
 */
String.indexOf = function(object) {
    var index = -1;
    for (var i = 0; i < this.length; i++) {
        if (this[i] == object) {
            index = i;
            break;
        }
    }
    return index;
};

/**
 * APIMethod: camelize
 * Camel-case a hyphenated string. 
 *     Ex. "chicken-head" becomes "chickenHead", and
 *     "-chicken-head" becomes "ChickenHead".
 * 
 * Return:
 * {String} The string, camelized
 */
String.prototype.camelize = function() {
    var oStringList = this.split('-');
    var camelizedString = oStringList[0];
    for (var i = 1; i < oStringList.length; i++) {
        var s = oStringList[i];
        camelizedString += s.charAt(0).toUpperCase() + s.substring(1);
    }
    return camelizedString;
};


/*********************
 *                   *
 *      NUMBER       * 
 *                   * 
 *********************/

/**
 * APIMethod: Number.limitSigDigs
 * Limit the number of significant digits on an integer. Does *not* work 
 *     with floats!
 * 
 * Parameters:
 * sig - {Integer}
 * 
 * Return:
 * {Integer} The number, rounded to the specified number of significant digits.
 *           If null, 0, or negative value passed in, returns 0
 */
Number.prototype.limitSigDigs = function(sig) {
    var number = (sig > 0) ? this.toString() : 0;
    if (sig < number.length) {
        var exp = number.length - sig;
        number = Math.round( this / Math.pow(10, exp)) * Math.pow(10, exp);
    }
    return parseInt(number);
}


/*********************
 *                   *
 *      FUNCTION     * 
 *                   * 
 *********************/

/**
 * APIMethod: Function.bind
 * Bind a function to an object. 
 * Method to easily create closures with 'this' altered.
 * <commit_msg>calling limitSigDigs() on a floater now raises an error. console console (Closes #862)<commit_after>/* Copyright (c) 2006-2007 MetaCarta, Inc., published under a modified BSD license.
 * See http://svn.openlayers.org/trunk/openlayers/repository-license.txt 
 * for the full text of the license. */

/**
 * Header: OpenLayers Base Types
 * Modifications to standard JavaScript types are described here.
 */

/*********************
 *                   *
 *      STRING       * 
 *                   * 
 *********************/


/**
 * APIMethod: String.startsWith
 * Whether or not a string starts with another string. 
 * 
 * Parameters:
 * sStart - {Sring} The string we're testing for.
 *  
 * Return:
 * {Boolean} Whether or not this string starts with the string passed in.
 */
String.prototype.startsWith = function(sStart) {
    return (this.substr(0,sStart.length) == sStart);
};

/**
 * APIMethod: String.contains
 * Whether or not a string contains another string.
 * 
 * Parameters:
 * str - {String} The string that we're testing for.
 * 
 * Return:
 * {Boolean} Whether or not this string contains with the string passed in.
 */
String.prototype.contains = function(str) {
    return (this.indexOf(str) != -1);
};

/**
 * APIMethod: String.trim
 * Removes leading and trailing whitespace characters from a string.
 * 
 * Return:
 * {String} A trimmed version of the string - all leading and 
 *          trailing spaces removed
 */
String.prototype.trim = function() {
    
    var b = 0;
    while(this.substr(b,1) == " ") {
        b++;
    }
    
    var e = this.length - 1;
    while(this.substr(e,1) == " ") {
        e--;
    }
    
    return this.substring(b, e+1);
};

/**
 * APIMethod: String.indexOf
 * Index of a character in a string.
 * 
 * Parameters:
 * object - {Object} Can be a string or a number
 * 
 * Return: 
 * {Integer} The index of the encountered object, or -1 if not found.
 */
String.indexOf = function(object) {
    var index = -1;
    for (var i = 0; i < this.length; i++) {
        if (this[i] == object) {
            index = i;
            break;
        }
    }
    return index;
};

/**
 * APIMethod: camelize
 * Camel-case a hyphenated string. 
 *     Ex. "chicken-head" becomes "chickenHead", and
 *     "-chicken-head" becomes "ChickenHead".
 * 
 * Return:
 * {String} The string, camelized
 */
String.prototype.camelize = function() {
    var oStringList = this.split('-');
    var camelizedString = oStringList[0];
    for (var i = 1; i < oStringList.length; i++) {
        var s = oStringList[i];
        camelizedString += s.charAt(0).toUpperCase() + s.substring(1);
    }
    return camelizedString;
};


/*********************
 *                   *
 *      NUMBER       * 
 *                   * 
 *********************/

/**
 * APIMethod: Number.limitSigDigs
 * Limit the number of significant digits on an integer. Does *not* work 
 *     with floats!
 * 
 * Parameters:
 * sig - {Integer}
 * 
 * Return:
 * {Integer} The number, rounded to the specified number of significant digits.
 *           If null, 0, or negative value passed in, returns 0
 */
Number.prototype.limitSigDigs = function(sig) {
    var numStr = (sig > 0) ? this.toString() : "0";
    if (numStr.contains(".")) {
        var msg = "limitSigDig can not be called on a floating point number";
        OpenLayers.Console.error(msg);
        return null;
    }
    if ( (sig > 0) && (sig < numStr.length) ) {
        var exp = numStr.length - sig;
        numStr = Math.round( this / Math.pow(10, exp)) * Math.pow(10, exp);
    }
    return parseInt(numStr);
}


/*********************
 *                   *
 *      FUNCTION     * 
 *                   * 
 *********************/

/**
 * APIMethod: Function.bind
 * Bind a function to an object. 
 * Method to easily create closures with 'this' altered.
 * 
{'fraction_non_alphanumeric': 0.15946529840669726, 'fraction_numerical': 0.008641641911963273, 'mean_word_length': 2.345528455284553, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6482538', 'n_tokens_mistral': 2335, 'n_tokens_neox': 2216, 'n_words': 683}