diff --git a/lib/util.js b/lib/util.js index 2181a2ca..70dd183c 100644 --- a/lib/util.js +++ b/lib/util.js @@ -473,8 +473,9 @@ * @param str * @param substr */ - this.rmStr = function(str, substr) { - var strArray = [], + this.rmStr = function(str, substr, isOnce) { + var replace, + strArray = [], isString = Util.isString(str), isArray = Util.isArray(substr); @@ -484,8 +485,13 @@ else strArray.push(substr); + if (isOnce) + replace = str.replace.bind(str); + else + replace = Util.replaceStr.bind(null, str); + strArray.forEach(function(strItem) { - str = Util.replace(str, strItem, ''); + str = replace(strItem, ''); }); } @@ -498,20 +504,9 @@ * @param substr */ this.rmStrOnce = function(str, substr) { - var n, isArray, - isString = Util.isString(str); + var ONCE = true; - if (isString && substr) { - n = substr.length; - isArray = Util.isArray(substr); - - if (!isArray) - str = str.replace(substr, ''); - else - Util.fori(n, function(i) { - str = str.replace(substr[i], ''); - }); - } + str = Util.rmStr(str, substr, ONCE); return str; };