/** * Overwritten String.substitute that is not replace the unmatched key with an empty string. */ String.implement( { substituteMatched: function(object, regexp){ return this.replace(regexp || (/\\?\{([^}]+)\}/g), function(match, name){ if (match.charAt(0) == '\\') return match.slice(1); return (object[name] != undefined) ? object[name] : match; }); } }); function $clone(obj) { if(obj == null || typeof(obj) != 'object') return obj; var temp = new obj.constructor(); for(var key in obj) temp[key] = $clone(obj[key]); return temp; }; function substituteAll(pSubject,pObject) { var subject = $clone(pSubject); if($chk(subject) && ($type(subject) == "object" || $type(subject) == "array")) { for(var i in subject) { value = subject[i]; if($type(value) == "string") subject[i] = value.substituteMatched(pObject); else subject[i] = substituteAll(value,pObject); } } else if($type(subject) == "string") subject = subject.substituteMatched(pObject); return subject; }