| Index: tools/telemetry/third_party/gsutil/third_party/protorpc/experimental/javascript/closure/string/string.js
|
| diff --git a/third_party/google_input_tools/third_party/closure_library/closure/goog/string/string.js b/tools/telemetry/third_party/gsutil/third_party/protorpc/experimental/javascript/closure/string/string.js
|
| similarity index 76%
|
| copy from third_party/google_input_tools/third_party/closure_library/closure/goog/string/string.js
|
| copy to tools/telemetry/third_party/gsutil/third_party/protorpc/experimental/javascript/closure/string/string.js
|
| index 90ee58cedc6d78d58a4a244ebcec416386d85d95..0725d09dec8bed300af7f5021b5381655e465074 100644
|
| --- a/third_party/google_input_tools/third_party/closure_library/closure/goog/string/string.js
|
| +++ b/tools/telemetry/third_party/gsutil/third_party/protorpc/experimental/javascript/closure/string/string.js
|
| @@ -25,13 +25,6 @@ goog.provide('goog.string.Unicode');
|
|
|
|
|
| /**
|
| - * @define {boolean} Enables HTML escaping of lowercase letter "e" which helps
|
| - * with detection of double-escaping as this letter is frequently used.
|
| - */
|
| -goog.define('goog.string.DETECT_DOUBLE_ESCAPING', false);
|
| -
|
| -
|
| -/**
|
| * Common Unicode string characters.
|
| * @enum {string}
|
| */
|
| @@ -90,18 +83,6 @@ goog.string.caseInsensitiveEndsWith = function(str, suffix) {
|
|
|
|
|
| /**
|
| - * Case-insensitive equality checker.
|
| - * @param {string} str1 First string to check.
|
| - * @param {string} str2 Second string to check.
|
| - * @return {boolean} True if {@code str1} and {@code str2} are the same string,
|
| - * ignoring case.
|
| - */
|
| -goog.string.caseInsensitiveEquals = function(str1, str2) {
|
| - return str1.toLowerCase() == str2.toLowerCase();
|
| -};
|
| -
|
| -
|
| -/**
|
| * Does simple python-style string substitution.
|
| * subs("foo%s hot%s", "bar", "dog") becomes "foobar hotdog".
|
| * @param {string} str The string containing the pattern.
|
| @@ -110,18 +91,18 @@ goog.string.caseInsensitiveEquals = function(str1, str2) {
|
| * {@code %s} has been replaced an argument from {@code var_args}.
|
| */
|
| goog.string.subs = function(str, var_args) {
|
| - var splitParts = str.split('%s');
|
| - var returnString = '';
|
| -
|
| - var subsArguments = Array.prototype.slice.call(arguments, 1);
|
| - while (subsArguments.length &&
|
| - // Replace up to the last split part. We are inserting in the
|
| - // positions between split parts.
|
| - splitParts.length > 1) {
|
| - returnString += splitParts.shift() + subsArguments.shift();
|
| + // This appears to be slow, but testing shows it compares more or less
|
| + // equivalent to the regex.exec method.
|
| + for (var i = 1; i < arguments.length; i++) {
|
| + // We cast to String in case an argument is a Function. Replacing $&, for
|
| + // example, with $$$& stops the replace from subsituting the whole match
|
| + // into the resultant string. $$$& in the first replace becomes $$& in the
|
| + // second, which leaves $& in the resultant string. Also:
|
| + // $$, $`, $', $n $nn
|
| + var replacement = String(arguments[i]).replace(/\$/g, '$$$$');
|
| + str = str.replace(/\%s/, replacement);
|
| }
|
| -
|
| - return returnString + splitParts.join('%s'); // Join unused '%s'
|
| + return str;
|
| };
|
|
|
|
|
| @@ -155,10 +136,9 @@ goog.string.isEmpty = function(str) {
|
|
|
|
|
| /**
|
| - * Checks if a string is null, undefined, empty or contains only whitespaces.
|
| + * Checks if a string is null, empty or contains only whitespaces.
|
| * @param {*} str The string to check.
|
| - * @return {boolean} True if{@code str} is null, undefined, empty, or
|
| - * whitespace only.
|
| + * @return {boolean} True if{@code str} is null, empty, or whitespace only.
|
| */
|
| goog.string.isEmptySafe = function(str) {
|
| return goog.string.isEmpty(goog.string.makeSafe(str));
|
| @@ -423,6 +403,14 @@ goog.string.numerateCompare = function(str1, str2) {
|
|
|
|
|
| /**
|
| + * Regular expression used for determining if a string needs to be encoded.
|
| + * @type {RegExp}
|
| + * @private
|
| + */
|
| +goog.string.encodeUriRegExp_ = /^[a-zA-Z0-9\-_.!~*'()]*$/;
|
| +
|
| +
|
| +/**
|
| * URL-encodes a string
|
| * @param {*} str The string to url-encode.
|
| * @return {string} An encoded copy of {@code str} that is safe for urls.
|
| @@ -430,7 +418,15 @@ goog.string.numerateCompare = function(str1, str2) {
|
| * of URLs *will* be encoded.
|
| */
|
| goog.string.urlEncode = function(str) {
|
| - return encodeURIComponent(String(str));
|
| + str = String(str);
|
| + // Checking if the search matches before calling encodeURIComponent avoids an
|
| + // extra allocation in IE6. This adds about 10us time in FF and a similiar
|
| + // over head in IE6 for lower working set apps, but for large working set
|
| + // apps like Gmail, it saves about 70us per call.
|
| + if (!goog.string.encodeUriRegExp_.test(str)) {
|
| + return encodeURIComponent(str);
|
| + }
|
| + return str;
|
| };
|
|
|
|
|
| @@ -457,17 +453,13 @@ goog.string.newLineToBr = function(str, opt_xml) {
|
|
|
|
|
| /**
|
| - * Escapes double quote '"' and single quote '\'' characters in addition to
|
| - * '&', '<', and '>' so that a string can be included in an HTML tag attribute
|
| - * value within double or single quotes.
|
| + * Escape double quote '"' characters in addition to '&', '<', and '>' so that a
|
| + * string can be included in an HTML tag attribute value within double quotes.
|
| *
|
| * It should be noted that > doesn't need to be escaped for the HTML or XML to
|
| * be valid, but it has been decided to escape it for consistency with other
|
| * implementations.
|
| *
|
| - * With goog.string.DETECT_DOUBLE_ESCAPING, this function escapes also the
|
| - * lowercase letter "e".
|
| - *
|
| * NOTE(user):
|
| * HtmlEscape is often called during the generation of large blocks of HTML.
|
| * Using statics for the regular expressions and strings is an optimization
|
| @@ -503,43 +495,28 @@ goog.string.newLineToBr = function(str, opt_xml) {
|
| goog.string.htmlEscape = function(str, opt_isLikelyToContainHtmlChars) {
|
|
|
| if (opt_isLikelyToContainHtmlChars) {
|
| - str = str.replace(goog.string.AMP_RE_, '&')
|
| - .replace(goog.string.LT_RE_, '<')
|
| - .replace(goog.string.GT_RE_, '>')
|
| - .replace(goog.string.QUOT_RE_, '"')
|
| - .replace(goog.string.SINGLE_QUOTE_RE_, ''')
|
| - .replace(goog.string.NULL_RE_, '�');
|
| - if (goog.string.DETECT_DOUBLE_ESCAPING) {
|
| - str = str.replace(goog.string.E_RE_, 'e');
|
| - }
|
| - return str;
|
| + return str.replace(goog.string.amperRe_, '&')
|
| + .replace(goog.string.ltRe_, '<')
|
| + .replace(goog.string.gtRe_, '>')
|
| + .replace(goog.string.quotRe_, '"');
|
|
|
| } else {
|
| // quick test helps in the case when there are no chars to replace, in
|
| // worst case this makes barely a difference to the time taken
|
| - if (!goog.string.ALL_RE_.test(str)) return str;
|
| + if (!goog.string.allRe_.test(str)) return str;
|
|
|
| // str.indexOf is faster than regex.test in this case
|
| if (str.indexOf('&') != -1) {
|
| - str = str.replace(goog.string.AMP_RE_, '&');
|
| + str = str.replace(goog.string.amperRe_, '&');
|
| }
|
| if (str.indexOf('<') != -1) {
|
| - str = str.replace(goog.string.LT_RE_, '<');
|
| + str = str.replace(goog.string.ltRe_, '<');
|
| }
|
| if (str.indexOf('>') != -1) {
|
| - str = str.replace(goog.string.GT_RE_, '>');
|
| + str = str.replace(goog.string.gtRe_, '>');
|
| }
|
| if (str.indexOf('"') != -1) {
|
| - str = str.replace(goog.string.QUOT_RE_, '"');
|
| - }
|
| - if (str.indexOf('\'') != -1) {
|
| - str = str.replace(goog.string.SINGLE_QUOTE_RE_, ''');
|
| - }
|
| - if (str.indexOf('\x00') != -1) {
|
| - str = str.replace(goog.string.NULL_RE_, '�');
|
| - }
|
| - if (goog.string.DETECT_DOUBLE_ESCAPING && str.indexOf('e') != -1) {
|
| - str = str.replace(goog.string.E_RE_, 'e');
|
| + str = str.replace(goog.string.quotRe_, '"');
|
| }
|
| return str;
|
| }
|
| @@ -548,68 +525,42 @@ goog.string.htmlEscape = function(str, opt_isLikelyToContainHtmlChars) {
|
|
|
| /**
|
| * Regular expression that matches an ampersand, for use in escaping.
|
| - * @const {!RegExp}
|
| + * @type {RegExp}
|
| * @private
|
| */
|
| -goog.string.AMP_RE_ = /&/g;
|
| +goog.string.amperRe_ = /&/g;
|
|
|
|
|
| /**
|
| * Regular expression that matches a less than sign, for use in escaping.
|
| - * @const {!RegExp}
|
| + * @type {RegExp}
|
| * @private
|
| */
|
| -goog.string.LT_RE_ = /</g;
|
| +goog.string.ltRe_ = /</g;
|
|
|
|
|
| /**
|
| * Regular expression that matches a greater than sign, for use in escaping.
|
| - * @const {!RegExp}
|
| + * @type {RegExp}
|
| * @private
|
| */
|
| -goog.string.GT_RE_ = />/g;
|
| +goog.string.gtRe_ = />/g;
|
|
|
|
|
| /**
|
| * Regular expression that matches a double quote, for use in escaping.
|
| - * @const {!RegExp}
|
| - * @private
|
| - */
|
| -goog.string.QUOT_RE_ = /"/g;
|
| -
|
| -
|
| -/**
|
| - * Regular expression that matches a single quote, for use in escaping.
|
| - * @const {!RegExp}
|
| - * @private
|
| - */
|
| -goog.string.SINGLE_QUOTE_RE_ = /'/g;
|
| -
|
| -
|
| -/**
|
| - * Regular expression that matches null character, for use in escaping.
|
| - * @const {!RegExp}
|
| - * @private
|
| - */
|
| -goog.string.NULL_RE_ = /\x00/g;
|
| -
|
| -
|
| -/**
|
| - * Regular expression that matches a lowercase letter "e", for use in escaping.
|
| - * @const {!RegExp}
|
| + * @type {RegExp}
|
| * @private
|
| */
|
| -goog.string.E_RE_ = /e/g;
|
| +goog.string.quotRe_ = /\"/g;
|
|
|
|
|
| /**
|
| * Regular expression that matches any character that needs to be escaped.
|
| - * @const {!RegExp}
|
| + * @type {RegExp}
|
| * @private
|
| */
|
| -goog.string.ALL_RE_ = (goog.string.DETECT_DOUBLE_ESCAPING ?
|
| - /[\x00&<>"'e]/ :
|
| - /[\x00&<>"']/);
|
| +goog.string.allRe_ = /[&<>\"]/;
|
|
|
|
|
| /**
|
| @@ -635,38 +586,15 @@ goog.string.unescapeEntities = function(str) {
|
|
|
|
|
| /**
|
| - * Unescapes a HTML string using the provided document.
|
| - *
|
| - * @param {string} str The string to unescape.
|
| - * @param {!Document} document A document to use in escaping the string.
|
| - * @return {string} An unescaped copy of {@code str}.
|
| - */
|
| -goog.string.unescapeEntitiesWithDocument = function(str, document) {
|
| - if (goog.string.contains(str, '&')) {
|
| - return goog.string.unescapeEntitiesUsingDom_(str, document);
|
| - }
|
| - return str;
|
| -};
|
| -
|
| -
|
| -/**
|
| * Unescapes an HTML string using a DOM to resolve non-XML, non-numeric
|
| * entities. This function is XSS-safe and whitespace-preserving.
|
| * @private
|
| * @param {string} str The string to unescape.
|
| - * @param {Document=} opt_document An optional document to use for creating
|
| - * elements. If this is not specified then the default window.document
|
| - * will be used.
|
| * @return {string} The unescaped {@code str} string.
|
| */
|
| -goog.string.unescapeEntitiesUsingDom_ = function(str, opt_document) {
|
| +goog.string.unescapeEntitiesUsingDom_ = function(str) {
|
| var seen = {'&': '&', '<': '<', '>': '>', '"': '"'};
|
| - var div;
|
| - if (opt_document) {
|
| - div = opt_document.createElement('div');
|
| - } else {
|
| - div = goog.global.document.createElement('div');
|
| - }
|
| + var div = document.createElement('div');
|
| // Match as many valid entity characters as possible. If the actual entity
|
| // happens to be shorter, it will still work as innerHTML will return the
|
| // trailing characters unchanged. Since the entity characters do not include
|
| @@ -749,23 +677,11 @@ goog.string.HTML_ENTITY_PATTERN_ = /&([^;\s<&]+);?/g;
|
| * @return {string} An escaped copy of {@code str}.
|
| */
|
| goog.string.whitespaceEscape = function(str, opt_xml) {
|
| - // This doesn't use goog.string.preserveSpaces for backwards compatibility.
|
| return goog.string.newLineToBr(str.replace(/ /g, '  '), opt_xml);
|
| };
|
|
|
|
|
| /**
|
| - * Preserve spaces that would be otherwise collapsed in HTML by replacing them
|
| - * with non-breaking space Unicode characters.
|
| - * @param {string} str The string in which to preserve whitespace.
|
| - * @return {string} A copy of {@code str} with preserved whitespace.
|
| - */
|
| -goog.string.preserveSpaces = function(str) {
|
| - return str.replace(/(^|[\n ]) /g, '$1' + goog.string.Unicode.NBSP);
|
| -};
|
| -
|
| -
|
| -/**
|
| * Strip quote characters around a string. The second argument is a string of
|
| * characters to treat as quotes. This can be a single character or a string of
|
| * multiple character and in that case each of those are treated as possible
|
| @@ -970,7 +886,7 @@ goog.string.escapeChar = function(c) {
|
| * characters in the string. The value for the key is set to true. You can
|
| * then use goog.object.map or goog.array.map to change the values.
|
| * @param {string} s The string to build the map from.
|
| - * @return {!Object} The map of characters used.
|
| + * @return {Object} The map of characters used.
|
| */
|
| // TODO(arv): It seems like we should have a generic goog.array.toMap. But do
|
| // we want a dependency on goog.array in goog.string?
|
| @@ -984,36 +900,13 @@ goog.string.toMap = function(s) {
|
|
|
|
|
| /**
|
| - * Determines whether a string contains a substring.
|
| - * @param {string} str The string to search.
|
| - * @param {string} subString The substring to search for.
|
| - * @return {boolean} Whether {@code str} contains {@code subString}.
|
| - */
|
| -goog.string.contains = function(str, subString) {
|
| - return str.indexOf(subString) != -1;
|
| -};
|
| -
|
| -
|
| -/**
|
| - * Determines whether a string contains a substring, ignoring case.
|
| - * @param {string} str The string to search.
|
| - * @param {string} subString The substring to search for.
|
| - * @return {boolean} Whether {@code str} contains {@code subString}.
|
| - */
|
| -goog.string.caseInsensitiveContains = function(str, subString) {
|
| - return goog.string.contains(str.toLowerCase(), subString.toLowerCase());
|
| -};
|
| -
|
| -
|
| -/**
|
| - * Returns the non-overlapping occurrences of ss in s.
|
| - * If either s or ss evalutes to false, then returns zero.
|
| - * @param {string} s The string to look in.
|
| - * @param {string} ss The string to look for.
|
| - * @return {number} Number of occurrences of ss in s.
|
| + * Checks whether a string contains a given character.
|
| + * @param {string} s The string to test.
|
| + * @param {string} ss The substring to test for.
|
| + * @return {boolean} True if {@code s} contains {@code ss}.
|
| */
|
| -goog.string.countOf = function(s, ss) {
|
| - return s && ss ? s.split(ss).length - 1 : 0;
|
| +goog.string.contains = function(s, ss) {
|
| + return s.indexOf(ss) != -1;
|
| };
|
|
|
|
|
| @@ -1284,7 +1177,7 @@ goog.string.createUniqueString = function() {
|
|
|
|
|
| /**
|
| - * Converts the supplied string to a number, which may be Infinity or NaN.
|
| + * Converts the supplied string to a number, which may be Ininity or NaN.
|
| * This function strips whitespace: (toNumber(' 123') === 123)
|
| * This function accepts scientific notation: (toNumber('1e1') === 10)
|
| *
|
| @@ -1304,31 +1197,11 @@ goog.string.toNumber = function(str) {
|
|
|
|
|
| /**
|
| - * Returns whether the given string is lower camel case (e.g. "isFooBar").
|
| - *
|
| - * Note that this assumes the string is entirely letters.
|
| - * @see http://en.wikipedia.org/wiki/CamelCase#Variations_and_synonyms
|
| - *
|
| - * @param {string} str String to test.
|
| - * @return {boolean} Whether the string is lower camel case.
|
| - */
|
| -goog.string.isLowerCamelCase = function(str) {
|
| - return /^[a-z]+([A-Z][a-z]*)*$/.test(str);
|
| -};
|
| -
|
| -
|
| -/**
|
| - * Returns whether the given string is upper camel case (e.g. "FooBarBaz").
|
| - *
|
| - * Note that this assumes the string is entirely letters.
|
| - * @see http://en.wikipedia.org/wiki/CamelCase#Variations_and_synonyms
|
| - *
|
| - * @param {string} str String to test.
|
| - * @return {boolean} Whether the string is upper camel case.
|
| + * A memoized cache for goog.string.toCamelCase.
|
| + * @type {Object.<string>}
|
| + * @private
|
| */
|
| -goog.string.isUpperCamelCase = function(str) {
|
| - return /^([A-Z][a-z]*)+$/.test(str);
|
| -};
|
| +goog.string.toCamelCaseCache_ = {};
|
|
|
|
|
| /**
|
| @@ -1339,13 +1212,23 @@ goog.string.isUpperCamelCase = function(str) {
|
| * @return {string} The string in camelCase form.
|
| */
|
| goog.string.toCamelCase = function(str) {
|
| - return String(str).replace(/\-([a-z])/g, function(all, match) {
|
| - return match.toUpperCase();
|
| - });
|
| + return goog.string.toCamelCaseCache_[str] ||
|
| + (goog.string.toCamelCaseCache_[str] =
|
| + String(str).replace(/\-([a-z])/g, function(all, match) {
|
| + return match.toUpperCase();
|
| + }));
|
| };
|
|
|
|
|
| /**
|
| + * A memoized cache for goog.string.toSelectorCase.
|
| + * @type {Object.<string>}
|
| + * @private
|
| + */
|
| +goog.string.toSelectorCaseCache_ = {};
|
| +
|
| +
|
| +/**
|
| * Converts a string from camelCase to selector-case (e.g. from
|
| * "multiPartString" to "multi-part-string"), useful for converting JS
|
| * style and dataset properties to equivalent CSS selectors and HTML keys.
|
| @@ -1353,124 +1236,7 @@ goog.string.toCamelCase = function(str) {
|
| * @return {string} The string in selector-case form.
|
| */
|
| goog.string.toSelectorCase = function(str) {
|
| - return String(str).replace(/([A-Z])/g, '-$1').toLowerCase();
|
| + return goog.string.toSelectorCaseCache_[str] ||
|
| + (goog.string.toSelectorCaseCache_[str] =
|
| + String(str).replace(/([A-Z])/g, '-$1').toLowerCase());
|
| };
|
| -
|
| -
|
| -/**
|
| - * Converts a string into TitleCase. First character of the string is always
|
| - * capitalized in addition to the first letter of every subsequent word.
|
| - * Words are delimited by one or more whitespaces by default. Custom delimiters
|
| - * can optionally be specified to replace the default, which doesn't preserve
|
| - * whitespace delimiters and instead must be explicitly included if needed.
|
| - *
|
| - * Default delimiter => " ":
|
| - * goog.string.toTitleCase('oneTwoThree') => 'OneTwoThree'
|
| - * goog.string.toTitleCase('one two three') => 'One Two Three'
|
| - * goog.string.toTitleCase(' one two ') => ' One Two '
|
| - * goog.string.toTitleCase('one_two_three') => 'One_two_three'
|
| - * goog.string.toTitleCase('one-two-three') => 'One-two-three'
|
| - *
|
| - * Custom delimiter => "_-.":
|
| - * goog.string.toTitleCase('oneTwoThree', '_-.') => 'OneTwoThree'
|
| - * goog.string.toTitleCase('one two three', '_-.') => 'One two three'
|
| - * goog.string.toTitleCase(' one two ', '_-.') => ' one two '
|
| - * goog.string.toTitleCase('one_two_three', '_-.') => 'One_Two_Three'
|
| - * goog.string.toTitleCase('one-two-three', '_-.') => 'One-Two-Three'
|
| - * goog.string.toTitleCase('one...two...three', '_-.') => 'One...Two...Three'
|
| - * goog.string.toTitleCase('one. two. three', '_-.') => 'One. two. three'
|
| - * goog.string.toTitleCase('one-two.three', '_-.') => 'One-Two.Three'
|
| - *
|
| - * @param {string} str String value in camelCase form.
|
| - * @param {string=} opt_delimiters Custom delimiter character set used to
|
| - * distinguish words in the string value. Each character represents a
|
| - * single delimiter. When provided, default whitespace delimiter is
|
| - * overridden and must be explicitly included if needed.
|
| - * @return {string} String value in TitleCase form.
|
| - */
|
| -goog.string.toTitleCase = function(str, opt_delimiters) {
|
| - var delimiters = goog.isString(opt_delimiters) ?
|
| - goog.string.regExpEscape(opt_delimiters) : '\\s';
|
| -
|
| - // For IE8, we need to prevent using an empty character set. Otherwise,
|
| - // incorrect matching will occur.
|
| - delimiters = delimiters ? '|[' + delimiters + ']+' : '';
|
| -
|
| - var regexp = new RegExp('(^' + delimiters + ')([a-z])', 'g');
|
| - return str.replace(regexp, function(all, p1, p2) {
|
| - return p1 + p2.toUpperCase();
|
| - });
|
| -};
|
| -
|
| -
|
| -/**
|
| - * Parse a string in decimal or hexidecimal ('0xFFFF') form.
|
| - *
|
| - * To parse a particular radix, please use parseInt(string, radix) directly. See
|
| - * https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/parseInt
|
| - *
|
| - * This is a wrapper for the built-in parseInt function that will only parse
|
| - * numbers as base 10 or base 16. Some JS implementations assume strings
|
| - * starting with "0" are intended to be octal. ES3 allowed but discouraged
|
| - * this behavior. ES5 forbids it. This function emulates the ES5 behavior.
|
| - *
|
| - * For more information, see Mozilla JS Reference: http://goo.gl/8RiFj
|
| - *
|
| - * @param {string|number|null|undefined} value The value to be parsed.
|
| - * @return {number} The number, parsed. If the string failed to parse, this
|
| - * will be NaN.
|
| - */
|
| -goog.string.parseInt = function(value) {
|
| - // Force finite numbers to strings.
|
| - if (isFinite(value)) {
|
| - value = String(value);
|
| - }
|
| -
|
| - if (goog.isString(value)) {
|
| - // If the string starts with '0x' or '-0x', parse as hex.
|
| - return /^\s*-?0x/i.test(value) ?
|
| - parseInt(value, 16) : parseInt(value, 10);
|
| - }
|
| -
|
| - return NaN;
|
| -};
|
| -
|
| -
|
| -/**
|
| - * Splits a string on a separator a limited number of times.
|
| - *
|
| - * This implementation is more similar to Python or Java, where the limit
|
| - * parameter specifies the maximum number of splits rather than truncating
|
| - * the number of results.
|
| - *
|
| - * See http://docs.python.org/2/library/stdtypes.html#str.split
|
| - * See JavaDoc: http://goo.gl/F2AsY
|
| - * See Mozilla reference: http://goo.gl/dZdZs
|
| - *
|
| - * @param {string} str String to split.
|
| - * @param {string} separator The separator.
|
| - * @param {number} limit The limit to the number of splits. The resulting array
|
| - * will have a maximum length of limit+1. Negative numbers are the same
|
| - * as zero.
|
| - * @return {!Array.<string>} The string, split.
|
| - */
|
| -
|
| -goog.string.splitLimit = function(str, separator, limit) {
|
| - var parts = str.split(separator);
|
| - var returnVal = [];
|
| -
|
| - // Only continue doing this while we haven't hit the limit and we have
|
| - // parts left.
|
| - while (limit > 0 && parts.length) {
|
| - returnVal.push(parts.shift());
|
| - limit--;
|
| - }
|
| -
|
| - // If there are remaining parts, append them to the end.
|
| - if (parts.length) {
|
| - returnVal.push(parts.join(separator));
|
| - }
|
| -
|
| - return returnVal;
|
| -};
|
| -
|
|
|