20 namespace Deveel.Data.Text {
47 private const char ZeroOrMoreChars =
'%';
48 private const char OneChar =
'_';
56 return (ch == OneChar || ch == ZeroOrMoreChars);
68 StringBuilder start =
new StringBuilder();
70 int len = pattern.Length;
72 bool lastEscapeChar =
false;
73 for (; i < len && rezt == null; ++i) {
76 lastEscapeChar =
false;
78 }
else if (c == escapeChar) {
79 lastEscapeChar =
true;
80 }
else if (IsWildCard(c)) {
81 rezt = pattern.Substring(i);
90 string st = start.ToString();
92 if (str.StartsWith(st)) {
93 string strRezt = str.Substring(st.Length);
95 return rezt.Length > 0 ? PatternMatch(rezt, strRezt, escapeChar) : strRezt.Length == 0;
129 public static bool PatternMatch(
string pattern,
string expression,
char escapeChar) {
133 if (pattern[0] == OneChar) {
140 bool finished = (i >= pattern.Length || expression.Length < 1);
141 bool lastWasEscape =
false;
145 if (!lastWasEscape && c == escapeChar) {
146 lastWasEscape =
true;
147 if (i >= expression.Length) {
151 }
else if (lastWasEscape || !IsWildCard(c)) {
152 lastWasEscape =
false;
155 if (i >= expression.Length || c != expression[i]) {
162 return PatternMatch(pattern.Substring(i), expression.Substring(i), escapeChar);
165 finished = (i >= pattern.Length);
169 int realPatternLength = 0;
170 int sz = pattern.Length;
171 for (
int n = 0; n < sz; ++n) {
172 if (pattern[n] != escapeChar) {
182 return realPatternLength == expression.Length;
191 if (pattern.Length == 1)
197 var nextString =
new StringBuilder();
199 bool finished1 = (i1 >= pattern.Length);
200 bool lastWasEscape1 =
false;
202 char nextChar = pattern[i1];
203 if (!lastWasEscape1 && nextChar == escapeChar) {
204 lastWasEscape1 =
true;
206 if (i1 >= pattern.Length) {
209 }
else if (lastWasEscape1 || !IsWildCard(nextChar)) {
210 lastWasEscape1 =
false;
211 nextString.Append(nextChar);
213 if (i1 >= pattern.Length) {
221 string findString = nextString.ToString();
228 if (i1 >= pattern.Length)
229 return (expression.EndsWith(findString));
235 int findStrLength = findString.Length;
236 int strIndex = expression.IndexOf(findString, 0);
238 while (strIndex != -1) {
239 bool matched = PatternMatch(
240 pattern.Substring(1 + findStrLength),
241 expression.Substring(strIndex + findStrLength),
247 strIndex = expression.IndexOf(findString, strIndex + 1);
static bool PatternMatch(string pattern, string expression, char escapeChar)
This is the pattern match recurrsive method.
static bool IsWildCard(char ch)
Returns true if the given character is a wild card (unknown).
This is a static class that performs the operations to do a pattern search on a given column of a tab...
static bool FullPatternMatch(string pattern, string str, char escapeChar)
Matches a pattern against a string and returns true if it matches or false otherwise.