feature(util) add getRegExp [from wild card]

This commit is contained in:
coderaiser 2014-08-09 05:15:01 -04:00
parent 7cf9fad27e
commit c78a357d96
2 changed files with 21 additions and 9 deletions

View file

@ -958,15 +958,7 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog;
if (type !== null) {
SelectType = type;
/* if type empty - select all files */
if (type === '')
type = '*';
type = '^' + type; /* search from start of line */
type = Util.replaceStr(type, '.', '\\.');
type = Util.replaceStr(type, '*', '.*');
type = Util.replaceStr(type, '?', '.?\\');
type += '$'; /* search to end of line */
type = Util.getRegExp(type);
n = files && files.length;
for (i = 0; i < n; i++) {

View file

@ -559,6 +559,26 @@
return str;
};
/**
* get regexp from wild card
*/
this.getRegExp = function(wildcard) {
var regExp;
if (!wildcard)
wildcard = '*';
wildcard = '^' + wildcard; /* search from start of line */
wildcard = Util.replaceStr(wildcard, '.', '\\.');
wildcard = Util.replaceStr(wildcard, '*', '.*');
wildcard = Util.replaceStr(wildcard, '?', '.?\\');
wildcard += '$'; /* search to end of line */
regExp = new RegExp(wildcard);
return regExp;
};
/**
* function render template with view
* @templ