mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-20 01:47:35 +00:00
refactor(util) isContainStr
This commit is contained in:
parent
e4012d1d1d
commit
f148a40ae0
1 changed files with 20 additions and 16 deletions
36
lib/util.js
36
lib/util.js
|
|
@ -332,30 +332,34 @@
|
|||
};
|
||||
|
||||
/**
|
||||
* function returns is pStr1 contains pStr2
|
||||
* @param pStr1
|
||||
* @param pStr2
|
||||
* function returns is str1 contains str2
|
||||
* @param str1
|
||||
* @param str2
|
||||
*/
|
||||
|
||||
this.isContainStr = function(pStr1, pStr2) {
|
||||
var i, n, str,
|
||||
ret = Util.isString(pStr1);
|
||||
this.isContainStr = function(str1, str2) {
|
||||
var i, n, str, is, index,
|
||||
isStr1 = Util.isString(str1),
|
||||
isStr2 = Util.isString(str2),
|
||||
isArray = Util.isArray(str2);
|
||||
|
||||
if (ret)
|
||||
if (Util.isArray(pStr2)) {
|
||||
n = pStr2.length;
|
||||
if (isStr1)
|
||||
if (isArray) {
|
||||
n = str2.length;
|
||||
|
||||
for(i = 0; i < n; i++) {
|
||||
str = pStr2[i];
|
||||
ret = Util.isContainStr(pStr1, str);
|
||||
for (i = 0; i < n; i++) {
|
||||
str = str2[i];
|
||||
is = Util.isContainStr(str1, str);
|
||||
|
||||
if (ret)
|
||||
if (is)
|
||||
break;
|
||||
}
|
||||
} else if (Util.isString(pStr2))
|
||||
ret = pStr1.indexOf(pStr2) >= 0;
|
||||
} else if (isStr2) {
|
||||
index = str1.indexOf(str2);
|
||||
is = index >= 0;
|
||||
}
|
||||
|
||||
return ret;
|
||||
return is;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue