diff --git a/src/mvc/Controller.js b/src/mvc/Controller.js index 98d5d331..3808c0bd 100755 --- a/src/mvc/Controller.js +++ b/src/mvc/Controller.js @@ -3,7 +3,7 @@ define(function(require) { var Connectivity = require('lavaca/net/Connectivity'), History = require('lavaca/net/History'), Disposable = require('lavaca/util/Disposable'), - StringUtils = require('lavaca/util/StringUtils'); + interpolate = require('mout/string/interpolate'); /** * Base type for controllers @@ -74,7 +74,8 @@ define(function(require) { * @return {String} The formatted URL */ url: function(str, args) { - return StringUtils.format(str, args, encodeURIComponent); + args = args.map(window.encodeURIComponent); + return interpolate(str, args, /\{(.+?)\}/); }, /** * Directs the user to another route diff --git a/src/util/StringUtils.js b/src/util/StringUtils.js deleted file mode 100755 index 4ca8aa20..00000000 --- a/src/util/StringUtils.js +++ /dev/null @@ -1,84 +0,0 @@ -define(function(require) { - - var _htmlEscapes = { - '&': '&', - '<': '<', - '>': '>', - '"': '"', - "'": ''' - }; - - function _noop(s) { - return s; - } - - /** - * Static utility type for working with strings - * @class lavaca.util.StringUtils - */ - var StringUtils = {}; - - /** - * Substitutes arguments into a string - * @method format - * @static - * @param {String} s The format string. Substitutions should be in the form {0} to sub in - * the first arg, {1} for the second, and so on - * @params {Object} arg Arguments to be substituted in to the string - * @return {String} The format string with the arguments substituted into it - */ - /** - * Substitutes arguments into a string - * @method format - * @static - * @param {String} s The format string. Substitutions should be in the form {0} to sub in - * the first arg, {1} for the second, and so on - * @param {Array} args Arguments to be substituted in to the string - * @return {String} The format string with the arguments substituted into it - */ - /** - * Substitutes arguments into a string - * @method format - * @static - * @param {String} s The format string. Substitutions should be in the form {0} to sub in - * the first arg, {1} for the second, and so on - * @param {Array} args Arguments to be substituted in to the string - * @param {Function} fn A function to call on each argument, the result of which is substituted into the string - * @return {String} The format string with the arguments substituted into it - */ - StringUtils.format = function(s /*[, arg0, arg1, argN]*/) { - var args, - fn = _noop, - i, - j; - if (arguments[1] instanceof Array) { - args = arguments[1]; - fn = arguments[2] || _noop; - } else { - args = [].slice.call(arguments, 1); - } - for (i = 0, j = args.length; i < j; i++) { - s = s.split('{' + i + '}').join(fn(args[i] + '')); - } - return s; - }; - - /** - * Escapes a string for inclusion in HTML - * @method escapeHTML - * @static - * - * @param {String} s The string - * @return {String} The escaped string - */ - StringUtils.escapeHTML = function(s) { - s = '' + s; - for (var n in _htmlEscapes) { - s = s.split(n).join(_htmlEscapes[n]); - } - return s; - }; - - return StringUtils; - -}); \ No newline at end of file diff --git a/test/unit/util/StringUtils.js b/test/unit/util/StringUtils.js deleted file mode 100755 index 672973c3..00000000 --- a/test/unit/util/StringUtils.js +++ /dev/null @@ -1,18 +0,0 @@ -define(function(require) { - - var StringUtils = require('lavaca/util/StringUtils'); - - describe('StringUtils', function() { - it('can format a string', function() { - var str = 'Bye {0}, hope you find your {1}'; - expect(StringUtils.format(str, ['Buddy', 'Dad'])).toEqual('Bye Buddy, hope you find your Dad'); - str = 'Hello {0}, bye {0}'; - expect(StringUtils.format(str, ['Dave'])).toEqual('Hello Dave, bye Dave'); - }); - it('can escape html', function() { - var str = '