From 5bd5ffbaf7de6436f8648591b9430dad1e3c1eef Mon Sep 17 00:00:00 2001 From: Wugy Date: Wed, 6 Jan 2010 14:22:31 +0100 Subject: default Dir in module/web/media/ --- module/web/media/default/js/sprintf.js | 123 +++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 module/web/media/default/js/sprintf.js (limited to 'module/web/media/default/js/sprintf.js') diff --git a/module/web/media/default/js/sprintf.js b/module/web/media/default/js/sprintf.js new file mode 100644 index 000000000..30d9046de --- /dev/null +++ b/module/web/media/default/js/sprintf.js @@ -0,0 +1,123 @@ +// JavaScript Document +sprintfWrapper = { + + init : function () { + + if (typeof arguments == "undefined") { return null; } + if (arguments.length < 1) { return null; } + if (typeof arguments[0] != "string") { return null; } + if (typeof RegExp == "undefined") { return null; } + + var string = arguments[0]; + var exp = new RegExp(/(%([%]|(\-)?(\+|\x20)?(0)?(\d+)?(\.(\d)?)?([bcdfosxX])))/g); + var matches = new Array(); + var strings = new Array(); + var convCount = 0; + var stringPosStart = 0; + var stringPosEnd = 0; + var matchPosEnd = 0; + var newString = ''; + var match = null; + + while (match = exp.exec(string)) { + if (match[9]) { convCount += 1; } + + stringPosStart = matchPosEnd; + stringPosEnd = exp.lastIndex - match[0].length; + strings[strings.length] = string.substring(stringPosStart, stringPosEnd); + + matchPosEnd = exp.lastIndex; + matches[matches.length] = { + match: match[0], + left: match[3] ? true : false, + sign: match[4] || '', + pad: match[5] || ' ', + min: match[6] || 0, + precision: match[8], + code: match[9] || '%', + negative: parseInt(arguments[convCount]) < 0 ? true : false, + argument: String(arguments[convCount]) + }; + } + strings[strings.length] = string.substring(matchPosEnd); + + if (matches.length == 0) { return string; } + if ((arguments.length - 1) < convCount) { return null; } + + var code = null; + var match = null; + var i = null; + + for (i=0; i