add simple string formating

This commit is contained in:
j 2010-11-25 12:47:42 +01:00
parent df324f8efa
commit fae9a7e541

View file

@ -1174,6 +1174,16 @@ Encoding functions
Format functions Format functions
================================================================================ ================================================================================
*/ */
Ox.format = function (s, args) {
/* Python(ish) string formatting:
* >>> format('{0}', ['zzz'])
* "zzz"
* >>> format('{x}', {x: 1})
* "1"
*/
var re = /\{([^}]+)\}/g;
return s.replace(re, function(_, match){ return args[match]; });
}
Ox.formatDate = function() { Ox.formatDate = function() {
/* /*
@ -1890,4 +1900,4 @@ Ox.isUndefined = function(val) {
true true
*/ */
return typeof val == "undefined"; return typeof val == "undefined";
}; };