Changeset 7529
- Timestamp:
- 03/06/07 07:11:03 (22 months ago)
- Files:
-
- 1 modified
-
trunk/src/string/extras.js (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/string/extras.js
r7503 r7529 5 5 dojo.require("dojo.lang.array"); 6 6 7 dojo.string.substitute = function(/*String*/template, /*Object or Array*/map, /* Object?*/thisObject){7 dojo.string.substitute = function(/*String*/template, /*Object or Array*/map, /*Function?*/transform, /*Object?*/thisObject){ 8 8 // summary: 9 9 // Performs parameterized substitutions on a string. Throws an exception if any parameter is unmatched. … … 18 18 // template: a string with expressions in the form ${key} to be replaced or ${key:format} which specifies a format function. NOTE syntax has changed from %{key} 19 19 // map: where to look for substitutions 20 // thisObject: where to look for optional format function 20 // transform: a function to process all parameters before substitution takes place, e.g. dojo.string.encodeXML 21 // thisObject: where to look for optional format function; default to the global namespace 21 22 22 23 return template.replace(/\$\{([^\s\:]+)(?:\:(\S+))?\}/g, function(match, key, format){ 23 var value = dojo.getObject(key,false,map); 24 if(typeof(value) == "undefined"){ 25 dojo.raise("Missing key: " + key); 26 } 27 return format ? dojo.getObject(format,false,thisObject)(value) : value; 24 var value = dojo.getObject(key,false,map).toString(); 25 if(format){ value = dojo.getObject(format,false,thisObject)(value);} 26 if(transform){ value = transform(value); } 27 return value; 28 28 }); // string 29 29 };