summaryrefslogtreecommitdiff
path: root/assets/viz/2/goog/string/string.js
diff options
context:
space:
mode:
Diffstat (limited to 'assets/viz/2/goog/string/string.js')
-rw-r--r--assets/viz/2/goog/string/string.js60
1 files changed, 35 insertions, 25 deletions
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);
}