199 lines
4.1 KiB
C#
199 lines
4.1 KiB
C#
using System;
|
|
|
|
namespace System.IO
|
|
{
|
|
// Token: 0x020001C7 RID: 455
|
|
internal class SearchPattern
|
|
{
|
|
// Token: 0x06001761 RID: 5985 RVA: 0x0005A660 File Offset: 0x00058860
|
|
public SearchPattern(string pattern)
|
|
: this(pattern, false)
|
|
{
|
|
}
|
|
|
|
// Token: 0x06001762 RID: 5986 RVA: 0x0005A66C File Offset: 0x0005886C
|
|
public SearchPattern(string pattern, bool ignore)
|
|
{
|
|
this.ignore = ignore;
|
|
this.Compile(pattern);
|
|
}
|
|
|
|
// Token: 0x06001764 RID: 5988 RVA: 0x0005A6C4 File Offset: 0x000588C4
|
|
public bool IsMatch(string text)
|
|
{
|
|
return this.Match(this.ops, text, 0);
|
|
}
|
|
|
|
// Token: 0x06001765 RID: 5989 RVA: 0x0005A6D4 File Offset: 0x000588D4
|
|
private void Compile(string pattern)
|
|
{
|
|
if (pattern == null || pattern.IndexOfAny(SearchPattern.InvalidChars) >= 0)
|
|
{
|
|
throw new ArgumentException("Invalid search pattern.");
|
|
}
|
|
if (pattern == "*")
|
|
{
|
|
this.ops = new SearchPattern.Op(SearchPattern.OpCode.True);
|
|
return;
|
|
}
|
|
this.ops = null;
|
|
int i = 0;
|
|
SearchPattern.Op op = null;
|
|
while (i < pattern.Length)
|
|
{
|
|
char c = pattern[i];
|
|
SearchPattern.Op op2;
|
|
if (c != '*')
|
|
{
|
|
if (c != '?')
|
|
{
|
|
op2 = new SearchPattern.Op(SearchPattern.OpCode.ExactString);
|
|
int num = pattern.IndexOfAny(SearchPattern.WildcardChars, i);
|
|
if (num < 0)
|
|
{
|
|
num = pattern.Length;
|
|
}
|
|
op2.Argument = pattern.Substring(i, num - i);
|
|
if (this.ignore)
|
|
{
|
|
op2.Argument = op2.Argument.ToLowerInvariant();
|
|
}
|
|
i = num;
|
|
}
|
|
else
|
|
{
|
|
op2 = new SearchPattern.Op(SearchPattern.OpCode.AnyChar);
|
|
i++;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
op2 = new SearchPattern.Op(SearchPattern.OpCode.AnyString);
|
|
i++;
|
|
}
|
|
if (op == null)
|
|
{
|
|
this.ops = op2;
|
|
}
|
|
else
|
|
{
|
|
op.Next = op2;
|
|
}
|
|
op = op2;
|
|
}
|
|
if (op == null)
|
|
{
|
|
this.ops = new SearchPattern.Op(SearchPattern.OpCode.End);
|
|
}
|
|
else
|
|
{
|
|
op.Next = new SearchPattern.Op(SearchPattern.OpCode.End);
|
|
}
|
|
}
|
|
|
|
// Token: 0x06001766 RID: 5990 RVA: 0x0005A810 File Offset: 0x00058A10
|
|
private bool Match(SearchPattern.Op op, string text, int ptr)
|
|
{
|
|
while (op != null)
|
|
{
|
|
switch (op.Code)
|
|
{
|
|
case SearchPattern.OpCode.ExactString:
|
|
{
|
|
int length = op.Argument.Length;
|
|
if (ptr + length > text.Length)
|
|
{
|
|
return false;
|
|
}
|
|
string text2 = text.Substring(ptr, length);
|
|
if (this.ignore)
|
|
{
|
|
text2 = text2.ToLowerInvariant();
|
|
}
|
|
if (text2 != op.Argument)
|
|
{
|
|
return false;
|
|
}
|
|
ptr += length;
|
|
break;
|
|
}
|
|
case SearchPattern.OpCode.AnyChar:
|
|
if (++ptr > text.Length)
|
|
{
|
|
return false;
|
|
}
|
|
break;
|
|
case SearchPattern.OpCode.AnyString:
|
|
while (ptr <= text.Length)
|
|
{
|
|
if (this.Match(op.Next, text, ptr))
|
|
{
|
|
return true;
|
|
}
|
|
ptr++;
|
|
}
|
|
return false;
|
|
case SearchPattern.OpCode.End:
|
|
return ptr == text.Length;
|
|
case SearchPattern.OpCode.True:
|
|
return true;
|
|
}
|
|
op = op.Next;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
// Token: 0x040006E9 RID: 1769
|
|
private SearchPattern.Op ops;
|
|
|
|
// Token: 0x040006EA RID: 1770
|
|
private bool ignore;
|
|
|
|
// Token: 0x040006EB RID: 1771
|
|
internal static readonly char[] WildcardChars = new char[] { '*', '?' };
|
|
|
|
// Token: 0x040006EC RID: 1772
|
|
internal static readonly char[] InvalidChars = new char[]
|
|
{
|
|
Path.DirectorySeparatorChar,
|
|
Path.AltDirectorySeparatorChar
|
|
};
|
|
|
|
// Token: 0x020001C8 RID: 456
|
|
private class Op
|
|
{
|
|
// Token: 0x06001767 RID: 5991 RVA: 0x0005A904 File Offset: 0x00058B04
|
|
public Op(SearchPattern.OpCode code)
|
|
{
|
|
this.Code = code;
|
|
this.Argument = null;
|
|
this.Next = null;
|
|
}
|
|
|
|
// Token: 0x040006ED RID: 1773
|
|
public SearchPattern.OpCode Code;
|
|
|
|
// Token: 0x040006EE RID: 1774
|
|
public string Argument;
|
|
|
|
// Token: 0x040006EF RID: 1775
|
|
public SearchPattern.Op Next;
|
|
}
|
|
|
|
// Token: 0x020001C9 RID: 457
|
|
private enum OpCode
|
|
{
|
|
// Token: 0x040006F1 RID: 1777
|
|
ExactString,
|
|
// Token: 0x040006F2 RID: 1778
|
|
AnyChar,
|
|
// Token: 0x040006F3 RID: 1779
|
|
AnyString,
|
|
// Token: 0x040006F4 RID: 1780
|
|
End,
|
|
// Token: 0x040006F5 RID: 1781
|
|
True
|
|
}
|
|
}
|
|
}
|