Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
FastString.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3
4public class FastString
5{
6 private string m_stringGenerated = "";
7
8 private bool m_isStringGenerated;
9
10 private char[] m_buffer;
11
12 private int m_bufferPos;
13
14 private int m_charsCapacity;
15
16 private List<char> m_replacement;
17
18 private object m_valueControl;
19
20 private int m_valueControlInt = int.MinValue;
21
22 public FastString(int initialCapacity = 32)
23 {
24 m_buffer = new char[m_charsCapacity = initialCapacity];
25 }
26
27 public bool IsEmpty()
28 {
30 {
31 return m_bufferPos == 0;
32 }
33 return m_stringGenerated == null;
34 }
35
36 public override string ToString()
37 {
39 {
40 m_stringGenerated = new string(m_buffer, 0, m_bufferPos);
42 }
43 return m_stringGenerated;
44 }
45
46 public bool IsModified(int newControlValue)
47 {
48 bool num = newControlValue != m_valueControlInt;
49 if (num)
50 {
51 m_valueControlInt = newControlValue;
52 }
53 return num;
54 }
55
56 public bool IsModified(object newControlValue)
57 {
58 bool num = !newControlValue.Equals(m_valueControl);
59 if (num)
60 {
61 m_valueControl = newControlValue;
62 }
63 return num;
64 }
65
66 public void Set(string str)
67 {
68 Clear();
69 Append(str);
72 }
73
74 public void Set(object str)
75 {
76 Set(str.ToString());
77 }
78
79 public void Set<T1, T2>(T1 str1, T2 str2)
80 {
81 Clear();
82 Append(str1);
83 Append(str2);
84 }
85
86 public void Set<T1, T2, T3>(T1 str1, T2 str2, T3 str3)
87 {
88 Clear();
89 Append(str1);
90 Append(str2);
91 Append(str3);
92 }
93
94 public void Set<T1, T2, T3, T4>(T1 str1, T2 str2, T3 str3, T4 str4)
95 {
96 Clear();
97 Append(str1);
98 Append(str2);
99 Append(str3);
100 Append(str4);
101 }
102
103 public void Set(params object[] str)
104 {
105 Clear();
106 for (int i = 0; i < str.Length; i++)
107 {
108 Append(str[i]);
109 }
110 }
111
113 {
114 m_bufferPos = 0;
115 m_isStringGenerated = false;
116 return this;
117 }
118
119 public FastString Append(string value)
120 {
121 ReallocateIFN(value.Length);
122 int length = value.Length;
123 for (int i = 0; i < length; i++)
124 {
125 m_buffer[m_bufferPos + i] = value[i];
126 }
127 m_bufferPos += length;
128 m_isStringGenerated = false;
129 return this;
130 }
131
132 public FastString Append(object value)
133 {
134 Append(value.ToString());
135 return this;
136 }
137
138 public FastString Append(int value)
139 {
140 ReallocateIFN(16);
141 if (value < 0)
142 {
143 value = -value;
144 m_buffer[m_bufferPos++] = '-';
145 }
146 int num = 0;
147 do
148 {
149 m_buffer[m_bufferPos++] = (char)(48 + value % 10);
150 value /= 10;
151 num++;
152 }
153 while (value != 0);
154 for (int num2 = num / 2 - 1; num2 >= 0; num2--)
155 {
156 char c = m_buffer[m_bufferPos - num2 - 1];
157 m_buffer[m_bufferPos - num2 - 1] = m_buffer[m_bufferPos - num + num2];
158 m_buffer[m_bufferPos - num + num2] = c;
159 }
160 m_isStringGenerated = false;
161 return this;
162 }
163
164 public FastString Append(float valueF)
165 {
166 double num = valueF;
167 m_isStringGenerated = false;
168 ReallocateIFN(32);
169 if (num == 0.0)
170 {
171 m_buffer[m_bufferPos++] = '0';
172 return this;
173 }
174 if (num < 0.0)
175 {
176 num = 0.0 - num;
177 m_buffer[m_bufferPos++] = '-';
178 }
179 int num2 = 0;
180 while (num < 1000000.0)
181 {
182 num *= 10.0;
183 num2++;
184 }
185 long num3 = (long)Math.Round(num);
186 int num4 = 0;
187 bool flag = true;
188 while (num3 != 0L || num2 >= 0)
189 {
190 if (num3 % 10 != 0L || num2 <= 0)
191 {
192 flag = false;
193 }
194 if (!flag)
195 {
196 m_buffer[m_bufferPos + num4++] = (char)(48 + num3 % 10);
197 }
198 if (--num2 == 0 && !flag)
199 {
200 m_buffer[m_bufferPos + num4++] = '.';
201 }
202 num3 /= 10;
203 }
204 m_bufferPos += num4;
205 for (int num5 = num4 / 2 - 1; num5 >= 0; num5--)
206 {
207 char c = m_buffer[m_bufferPos - num5 - 1];
208 m_buffer[m_bufferPos - num5 - 1] = m_buffer[m_bufferPos - num4 + num5];
209 m_buffer[m_bufferPos - num4 + num5] = c;
210 }
211 return this;
212 }
213
214 public FastString Replace(string oldStr, string newStr)
215 {
216 if (m_bufferPos == 0)
217 {
218 return this;
219 }
220 if (m_replacement == null)
221 {
222 m_replacement = new List<char>();
223 }
224 for (int i = 0; i < m_bufferPos; i++)
225 {
226 bool flag = false;
227 if (m_buffer[i] == oldStr[0])
228 {
229 int j;
230 for (j = 1; j < oldStr.Length && m_buffer[i + j] == oldStr[j]; j++)
231 {
232 }
233 flag = j >= oldStr.Length;
234 }
235 if (flag)
236 {
237 i += oldStr.Length - 1;
238 if (newStr != null)
239 {
240 for (int k = 0; k < newStr.Length; k++)
241 {
242 m_replacement.Add(newStr[k]);
243 }
244 }
245 }
246 else
247 {
248 m_replacement.Add(m_buffer[i]);
249 }
250 }
252 for (int l = 0; l < m_replacement.Count; l++)
253 {
254 m_buffer[l] = m_replacement[l];
255 }
257 m_replacement.Clear();
258 m_isStringGenerated = false;
259 return this;
260 }
261
262 private void ReallocateIFN(int nbCharsToAdd)
263 {
264 if (m_bufferPos + nbCharsToAdd > m_charsCapacity)
265 {
266 m_charsCapacity = Math.Max(m_charsCapacity + nbCharsToAdd, m_charsCapacity * 2);
267 char[] array = new char[m_charsCapacity];
268 m_buffer.CopyTo(array, 0);
269 m_buffer = array;
270 }
271 }
272}
override string ToString()
Definition: FastString.cs:36
FastString Append(int value)
Definition: FastString.cs:138
bool m_isStringGenerated
Definition: FastString.cs:8
List< char > m_replacement
Definition: FastString.cs:16
FastString Append(string value)
Definition: FastString.cs:119
string m_stringGenerated
Definition: FastString.cs:6
object m_valueControl
Definition: FastString.cs:18
void Set(object str)
Definition: FastString.cs:74
char[] m_buffer
Definition: FastString.cs:10
FastString Clear()
Definition: FastString.cs:112
int m_valueControlInt
Definition: FastString.cs:20
FastString(int initialCapacity=32)
Definition: FastString.cs:22
FastString Replace(string oldStr, string newStr)
Definition: FastString.cs:214
bool IsEmpty()
Definition: FastString.cs:27
void Set< T1, T2 >(T1 str1, T2 str2)
Definition: FastString.cs:79
bool IsModified(object newControlValue)
Definition: FastString.cs:56
FastString Append(object value)
Definition: FastString.cs:132
void Set(params object[] str)
Definition: FastString.cs:103
void Set< T1, T2, T3 >(T1 str1, T2 str2, T3 str3)
Definition: FastString.cs:86
FastString Append(float valueF)
Definition: FastString.cs:164
int m_bufferPos
Definition: FastString.cs:12
void Set< T1, T2, T3, T4 >(T1 str1, T2 str2, T3 str3, T4 str4)
Definition: FastString.cs:94
void Set(string str)
Definition: FastString.cs:66
void ReallocateIFN(int nbCharsToAdd)
Definition: FastString.cs:262
bool IsModified(int newControlValue)
Definition: FastString.cs:46
int m_charsCapacity
Definition: FastString.cs:14