Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
LikeNode.cs
Go to the documentation of this file.
4
5namespace System.Data;
6
7internal sealed class LikeNode : BinaryNode
8{
9 private static readonly char[] s_trimChars = new char[2] { ' ', '\u3000' };
10
11 private int _kind;
12
13 private string _pattern;
14
15 internal LikeNode(DataTable table, int op, ExpressionNode left, ExpressionNode right)
16 : base(table, op, left, right)
17 {
18 }
19
20 [RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")]
21 internal override object Eval(DataRow row, DataRowVersion version)
22 {
23 object obj = _left.Eval(row, version);
25 {
26 return DBNull.Value;
27 }
28 string text;
29 if (_pattern == null)
30 {
31 object obj2 = _right.Eval(row, version);
32 if (!(obj2 is string) && !(obj2 is SqlString))
33 {
34 SetTypeMismatchError(_op, obj.GetType(), obj2.GetType());
35 }
36 if (obj2 == DBNull.Value || DataStorage.IsObjectSqlNull(obj2))
37 {
38 return DBNull.Value;
39 }
40 string pat = (string)SqlConvert.ChangeType2(obj2, StorageType.String, typeof(string), base.FormatProvider);
41 text = AnalyzePattern(pat);
42 if (_right.IsConstant())
43 {
44 _pattern = text;
45 }
46 }
47 else
48 {
49 text = _pattern;
50 }
51 if (!(obj is string) && !(obj is SqlString))
52 {
53 SetTypeMismatchError(_op, obj.GetType(), typeof(string));
54 }
55 string text2 = ((obj is SqlString sqlString) ? sqlString.Value : ((string)obj));
56 string s = text2.TrimEnd(s_trimChars);
57 switch (_kind)
58 {
59 case 5:
60 return true;
61 case 4:
62 return base.table.Compare(s, text) == 0;
63 case 3:
64 return 0 <= base.table.IndexOf(s, text);
65 case 1:
66 return base.table.IndexOf(s, text) == 0;
67 case 2:
68 {
69 string s2 = text.TrimEnd(s_trimChars);
70 return base.table.IsSuffix(s, s2);
71 }
72 default:
73 return DBNull.Value;
74 }
75 }
76
77 internal string AnalyzePattern(string pat)
78 {
79 int length = pat.Length;
80 char[] array = new char[length + 1];
81 pat.CopyTo(0, array, 0, length);
82 array[length] = '\0';
83 string text = null;
84 char[] array2 = new char[length + 1];
85 int num = 0;
86 int num2 = 0;
87 int i = 0;
88 while (i < length)
89 {
90 if (array[i] == '*' || array[i] == '%')
91 {
92 for (; (array[i] == '*' || array[i] == '%') && i < length; i++)
93 {
94 }
95 if ((i < length && num > 0) || num2 >= 2)
96 {
98 }
99 num2++;
100 }
101 else if (array[i] == '[')
102 {
103 i++;
104 if (i >= length)
105 {
106 throw ExprException.InvalidPattern(pat);
107 }
108 array2[num++] = array[i++];
109 if (i >= length)
110 {
111 throw ExprException.InvalidPattern(pat);
112 }
113 if (array[i] != ']')
114 {
115 throw ExprException.InvalidPattern(pat);
116 }
117 i++;
118 }
119 else
120 {
121 array2[num++] = array[i];
122 i++;
123 }
124 }
125 text = new string(array2, 0, num);
126 if (num2 == 0)
127 {
128 _kind = 4;
129 }
130 else if (num > 0)
131 {
132 if (array[0] == '*' || array[0] == '%')
133 {
134 if (array[length - 1] == '*' || array[length - 1] == '%')
135 {
136 _kind = 3;
137 }
138 else
139 {
140 _kind = 2;
141 }
142 }
143 else
144 {
145 _kind = 1;
146 }
147 }
148 else
149 {
150 _kind = 5;
151 }
152 return text;
153 }
154}
static readonly DBNull Value
Definition DBNull.cs:8
ExpressionNode _left
Definition BinaryNode.cs:51
void SetTypeMismatchError(int op, Type left, Type right)
ExpressionNode _right
Definition BinaryNode.cs:53
static bool IsObjectSqlNull(object value)
static object ChangeType2(object value, StorageType stype, Type type, IFormatProvider formatProvider)
static Exception InvalidPattern(string pat)
LikeNode(DataTable table, int op, ExpressionNode left, ExpressionNode right)
Definition LikeNode.cs:15
static readonly char[] s_trimChars
Definition LikeNode.cs:9
string AnalyzePattern(string pat)
Definition LikeNode.cs:77
override object Eval(DataRow row, DataRowVersion version)
Definition LikeNode.cs:21