From cf0203f56ab23ec1b47b0cd458111b66cee7af2c Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Mon, 3 Dec 2012 19:40:12 +0530 Subject: [PATCH] use split-join instead of replace in repl --- public/js/legacy/utils/datatype.js | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/public/js/legacy/utils/datatype.js b/public/js/legacy/utils/datatype.js index fbdbde33b0..ac99e19e03 100644 --- a/public/js/legacy/utils/datatype.js +++ b/public/js/legacy/utils/datatype.js @@ -205,22 +205,11 @@ var rstrip = function(s, chars) { return s; } -function repl_all(s, s1, s2) { - var idx = s.indexOf(s1); - if(cstr(s2).indexOf(s1)!=-1) { - console.log("infinite loop in repl = " + s1 + "\n\n" + s2); - return s; - } - - while (idx != -1){ - s = s.replace(s1, s2 || ""); - idx = s.indexOf(s1); - } - return s; -} function repl(s, dict) { if(s==null)return ''; - for(key in dict) s = repl_all(s, '%('+key+')s', dict[key]); + for(key in dict) { + s = s.split("%("+key+")s").join(dict[key]); + } return s; }