Allows you to define a tokenized string and pass an arbitrary number of arguments to replace the tokens. Each token must be unique, and must increment in the format {0}, {1}, etc.
The following Ext.String.format is modified to accept formatters functions (Ext.util.Format)
e.g.
alert(Ext.String.format("{0} {1:usMoney} {2:date('Y-m-d')}", 10, 20, new Date()));
Here is modified code
Code:
Ext.String._formatRe = /{(\d+)(?:\:([\w.])(?:((.?)?))?)?}/g;
Ext.String._argRe = /(['"])(.?)\1\s(?:,|$)/g
Ext.String.format = function(format) {
var args = Ext.Array.toArray(arguments, 1),
fm = Ext.util.Format;
return format.replace(Ext.String._formatRe, function(m, idx, fn, fmArgs) {
var replaceValue = args[parseInt(idx, 10)],
values,
match;
if (fn) {
values = [replaceValue];
while (match = Ext.String._argRe.exec(fmArgs)) {
values.push(match[2]);
}
return fm[fn].apply(fm, values);
}
return replaceValue;
});
};