refactor(util) rmStr, rmStrOnce

This commit is contained in:
coderaiser 2014-05-10 11:26:31 -04:00
parent 4d2ed0542f
commit 85eb6a8027

View file

@ -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;
};