summaryrefslogtreecommitdiffstats
path: root/chromium/chrome/third_party/chromevox/third_party/closure-library/closure/goog/string/string.js
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/chrome/third_party/chromevox/third_party/closure-library/closure/goog/string/string.js')
-rw-r--r--chromium/chrome/third_party/chromevox/third_party/closure-library/closure/goog/string/string.js47
1 files changed, 47 insertions, 0 deletions
diff --git a/chromium/chrome/third_party/chromevox/third_party/closure-library/closure/goog/string/string.js b/chromium/chrome/third_party/chromevox/third_party/closure-library/closure/goog/string/string.js
new file mode 100644
index 00000000000..af1046004e2
--- /dev/null
+++ b/chromium/chrome/third_party/chromevox/third_party/closure-library/closure/goog/string/string.js
@@ -0,0 +1,47 @@
+// Copyright 2006 The Closure Library Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS-IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+/**
+ * @fileoverview Utilities for string manipulation.
+ */
+
+
+/**
+ * Namespace for string utilities
+ */
+goog.provide('goog.string');
+
+
+/**
+ * Does simple python-style string substitution.
+ * subs("foo%s hot%s", "bar", "dog") becomes "foobar hotdog".
+ * @param {string} str The string containing the pattern.
+ * @param {...*} var_args The items to substitute into the pattern.
+ * @return {string} A copy of {@code str} in which each occurrence of
+ * {@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();
+ }
+
+ return returnString + splitParts.join('%s'); // Join unused '%s'
+};