1 using System;
2 using System.Collections;
3
4
5
6
7
8 namespace System.RegularExpressions
9 {
10 public ustring MakeRegularExpressionPatternFromFilePattern(const ustring& filePattern)
11 {
12 ustring pattern;
13 for (uchar c : filePattern)
14 {
15 switch (c)
16 {
17 case '.': pattern.Append(u"\\.");
18 break;
19 case '*': pattern.Append(u".*");
20 break;
21 case '?': pattern.Append(u".");
22 break;
23 default: pattern.Append(c, 1);
24 break;
25 }
26 }
27 return pattern;
28 }
29 public bool FilePatternMatch(const ustring& filePath, const ustring& filePattern)
30 {
31 return PatternMatch(filePath, MakeRegularExpressionPatternFromFilePattern(filePattern));
32 }
33 public bool PatternMatch(const ustring& str, const ustring& regularExpressionPattern)
34 {
35 Context context;
36 Nfa nfa = CompileRegularExpressionPattern(context, regularExpressionPattern);
37 return PatternMatch(str, nfa);
38 }
39 public Nfa CompileRegularExpressionPattern(Context& context, const ustring& regularExpressionPattern)
40 {
41 RexLexer lexer(regularExpressionPattern, "", 0);
42 return RexParser.Parse(lexer, &context);
43 }
44 public Nfa CompileFilePattern(Context& context, const ustring& filePattern)
45 {
46 return CompileRegularExpressionPattern(context, MakeRegularExpressionPatternFromFilePattern(filePattern));
47 }
48 public bool PatternMatch(const ustring& str, Nfa& nfa)
49 {
50 return Match(nfa, str);
51 }
52 }