diff options
Diffstat (limited to 'assets/viz/2/goog/string')
-rw-r--r-- | assets/viz/2/goog/string/const.js | 12 | ||||
-rw-r--r-- | assets/viz/2/goog/string/string.js | 60 | ||||
-rw-r--r-- | assets/viz/2/goog/string/typedstring.js | 2 |
3 files changed, 44 insertions, 30 deletions
diff --git a/assets/viz/2/goog/string/const.js b/assets/viz/2/goog/string/const.js index 7f919be..30bfc4e 100644 --- a/assets/viz/2/goog/string/const.js +++ b/assets/viz/2/goog/string/const.js @@ -56,7 +56,7 @@ goog.string.Const = function() { /** * A type marker used to implement additional run-time type checking. * @see goog.string.Const#unwrap - * @const + * @const {!Object} * @private */ this.STRING_CONST_TYPE_MARKER__GOOG_STRING_SECURITY_PRIVATE_ = @@ -148,9 +148,6 @@ goog.string.Const.unwrap = function(stringConst) { * var t = goog.string.Const.from('hello' + world); * </pre> * - * TODO(xtof): Compile-time checks that this function is only called - * with compile-time constant expressions. - * * @param {string} s A constant string from which to create a Const. * @return {!goog.string.Const} A Const object initialized to stringConst. */ @@ -180,3 +177,10 @@ goog.string.Const.create__googStringSecurityPrivate_ = function(s) { s; return stringConst; }; + + +/** + * A Const instance wrapping the empty string. + * @const {!goog.string.Const} + */ +goog.string.Const.EMPTY = goog.string.Const.from(''); diff --git a/assets/viz/2/goog/string/string.js b/assets/viz/2/goog/string/string.js index a2f7003..7a10ae0 100644 --- a/assets/viz/2/goog/string/string.js +++ b/assets/viz/2/goog/string/string.js @@ -91,9 +91,9 @@ goog.string.caseInsensitiveStartsWith = function(str, prefix) { * case). */ goog.string.caseInsensitiveEndsWith = function(str, suffix) { - return goog.string.caseInsensitiveCompare( - suffix, str.substr(str.length - suffix.length, suffix.length)) == - 0; + return ( + goog.string.caseInsensitiveCompare( + suffix, str.substr(str.length - suffix.length, suffix.length)) == 0); }; @@ -175,11 +175,9 @@ goog.string.isEmptyString = function(str) { /** * Checks if a string is empty or contains only whitespaces. * - * TODO(user): Deprecate this when clients have been switched over to - * goog.string.isEmptyOrWhitespace. - * * @param {string} str The string to check. * @return {boolean} Whether {@code str} is empty or whitespace only. + * @deprecated Use goog.string.isEmptyOrWhitespace instead. */ goog.string.isEmpty = goog.string.isEmptyOrWhitespace; @@ -200,12 +198,10 @@ goog.string.isEmptyOrWhitespaceSafe = function(str) { /** * Checks if a string is null, undefined, empty or contains only whitespaces. * - * TODO(user): Deprecate this when clients have been switched over to - * goog.string.isEmptyOrWhitespaceSafe. - * * @param {*} str The string to check. * @return {boolean} Whether {@code str} is null, undefined, empty, or * whitespace only. + * @deprecated Use goog.string.isEmptyOrWhitespace instead. */ goog.string.isEmptySafe = goog.string.isEmptyOrWhitespaceSafe; @@ -998,7 +994,7 @@ goog.string.quote = function(s) { /** - * Takes a string and returns the escaped string for that character. + * Takes a string and returns the escaped string for that input string. * @param {string} str The string to escape. * @return {string} An escaped string representing {@code str}. */ @@ -1105,15 +1101,14 @@ goog.string.removeAt = function(s, index, stringLength) { /** - * Removes the first occurrence of a substring from a string. - * @param {string} s The base string from which to remove. - * @param {string} ss The string to remove. - * @return {string} A copy of {@code s} with {@code ss} removed or the full - * string if nothing is removed. + * Removes the first occurrence of a substring from a string. + * @param {string} str The base string from which to remove. + * @param {string} substr The string to remove. + * @return {string} A copy of {@code str} with {@code substr} removed or the + * full string if nothing is removed. */ -goog.string.remove = function(s, ss) { - var re = new RegExp(goog.string.regExpEscape(ss), ''); - return s.replace(re, ''); +goog.string.remove = function(str, substr) { + return str.replace(substr, ''); }; @@ -1131,6 +1126,20 @@ goog.string.removeAll = function(s, ss) { /** + * Replaces all occurrences of a substring of a string with a new substring. + * @param {string} s The base string from which to remove. + * @param {string} ss The string to replace. + * @param {string} replacement The replacement string. + * @return {string} A copy of {@code s} with {@code ss} replaced by + * {@code replacement} or the original string if nothing is replaced. + */ +goog.string.replaceAll = function(s, ss, replacement) { + var re = new RegExp(goog.string.regExpEscape(ss), 'g'); + return s.replace(re, replacement.replace(/\$/g, '$$$$')); +}; + + +/** * Escapes characters in the string that are not safe to use in a RegExp. * @param {*} s The string to escape. If not a string, it will be casted * to one. @@ -1251,14 +1260,12 @@ goog.string.compareVersions = function(version1, version2) { var v1Sub = v1Subs[subIdx] || ''; var v2Sub = v2Subs[subIdx] || ''; - // Split the subversions into pairs of numbers and qualifiers (like 'b'). - // Two different RegExp objects are needed because they are both using - // the 'g' flag. - var v1CompParser = new RegExp('(\\d*)(\\D*)', 'g'); - var v2CompParser = new RegExp('(\\d*)(\\D*)', 'g'); do { - var v1Comp = v1CompParser.exec(v1Sub) || ['', '', '']; - var v2Comp = v2CompParser.exec(v2Sub) || ['', '', '']; + // Split the subversions into pairs of numbers and qualifiers (like 'b'). + // Two different RegExp objects are use to make it clear the code + // is side-effect free + var v1Comp = /(\d*)(\D*)(.*)/.exec(v1Sub) || ['', '', '', '']; + var v2Comp = /(\d*)(\D*)(.*)/.exec(v2Sub) || ['', '', '', '']; // Break if there are no more matches. if (v1Comp[0].length == 0 && v2Comp[0].length == 0) { break; @@ -1278,6 +1285,9 @@ goog.string.compareVersions = function(version1, version2) { v1Comp[2].length == 0, v2Comp[2].length == 0) || goog.string.compareElements_(v1Comp[2], v2Comp[2]); // Stop as soon as an inequality is discovered. + + v1Sub = v1Comp[3]; + v2Sub = v2Comp[3]; } while (order == 0); } diff --git a/assets/viz/2/goog/string/typedstring.js b/assets/viz/2/goog/string/typedstring.js index 075115f..d0d7bd9 100644 --- a/assets/viz/2/goog/string/typedstring.js +++ b/assets/viz/2/goog/string/typedstring.js @@ -43,6 +43,6 @@ goog.string.TypedString.prototype.implementsGoogStringTypedString; /** * Retrieves this wrapped string's value. - * @return {!string} The wrapped string's value. + * @return {string} The wrapped string's value. */ goog.string.TypedString.prototype.getTypedStringValue; |