//glob 模式匹配 namespace string; class glob { ctor( pattern ){ this.push = function(pattern){ if(type(pattern) === "table"){ pattern = ..table.unique(pattern); for(i=1;#pattern;1){ ..table.push(this, convert(pattern[i]) ) } } else { ..table.push(this,convert(pattern)) } } if(pattern){ this.push(pattern) pattern = null; } }; load = function(path){ if(..io.exist(path)){ for(line in ..io.lines(path)){ line = ..string.trim(line); if(!#line) continue; if(line[1]!='#'#) ..table.push(this,convert(line)) } } }; clear = function(){ if(#this){ ..table.splice(this,1,#this); } }; test = function(str){ for(i=1;#this;1){ if( ..string.find(str,this[i] ) )return true; } }; } namespace glob { convert = function(pattern){ if(pattern[1]==='^'){ return pattern } var set = false; pattern = "^" + ..string.replaceUnmatched(pattern,"<\*\*>|\p",function(c) { if( c==="*" ) return "[^\\]*?"; if( c==="**" ) return ".*?"; if( c==="?" ) return "[^\\]"; return "\"+c; },"\[[^\]]*\]") + "$" pattern = ..string.replace(pattern,"\[\!([^\]]*\])","[^\1"); return (..string.replace(pattern,"/","\\")); } } /**intellisense() string.glob = glob 模式匹配工具。\n\nglob 模式用于匹配文件名或文件路径,主要通配符包括:\n- `*` 匹配任意个字符(不含路径分隔符)\n- `**` 匹配任意层级的目录(含路径分隔符)\n- `?` 匹配单个字符\n`[abc]` 匹配方括号中的任意单个字符\n- `[!abc]` 或 `[^abc]` 匹配不在方括号中的任意单个字符。\n\n注意:`\` 不用于转义,模式中的`/`自动转换为`\`进行匹配。 string.glob( = 创建 glob 模式匹配工具 string.glob(.(pattern) = glob 模式匹配工具。\n参数 @pattern 可指定符合 glob 语法的模式文本,或包含模式文本的数组。\n可省略参数。 string.glob() = !string_glob. !string_glob.test(__) = 测试一个字符串是否匹配 !string_glob.push(__/*模式*/) = 添加 glob 模式。\n参数 @1 可以是符合 glob 语法的模式文本,或包含模式文本的数组 !string_glob.load(__/*模式文件*/) = 自文件加载并添加 glob 模式,不清空之前的模式。\n每行文本指定一个模式,#字符开头的为注释,\n忽略首尾空格,忽略空行 !string_glob.clear() = 清空所有 glob 模式。 end intellisense**/