Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
DateTimeFormatInfoScanner.cs
Go to the documentation of this file.
2using System.Text;
3
5
6internal sealed class DateTimeFormatInfoScanner
7{
8 private enum FoundDatePattern
9 {
10 None = 0,
15 }
16
18
20
21 internal static int SkipWhiteSpacesAndNonLetter(string pattern, int currentIndex)
22 {
23 while (currentIndex < pattern.Length)
24 {
25 char c = pattern[currentIndex];
26 if (c == '\\')
27 {
28 currentIndex++;
29 if (currentIndex >= pattern.Length)
30 {
31 break;
32 }
33 c = pattern[currentIndex];
34 if (c == '\'')
35 {
36 continue;
37 }
38 }
39 if (char.IsLetter(c) || c == '\'' || c == '.')
40 {
41 break;
42 }
43 currentIndex++;
44 }
45 return currentIndex;
46 }
47
48 internal void AddDateWordOrPostfix(string formatPostfix, string str)
49 {
50 if (str.Length == 0)
51 {
52 return;
53 }
54 if (str.Length == 1)
55 {
56 switch (str[0])
57 {
58 case '.':
60 return;
61 case '-':
62 case '/':
63 case '分':
64 case '年':
65 case '日':
66 case '时':
67 case '時':
68 case '月':
69 case '秒':
70 case '년':
71 case '분':
72 case '시':
73 case '월':
74 case '일':
75 case '초':
76 return;
77 }
78 }
79 if (m_dateWords == null)
80 {
82 }
83 if (formatPostfix == "MMMM")
84 {
85 string item = "\ue000" + str;
87 {
89 }
90 return;
91 }
93 {
95 }
96 if (str[^1] == '.')
97 {
98 string item2 = str[0..^1];
100 {
102 }
103 }
104 }
105
106 internal int AddDateWords(string pattern, int index, string formatPostfix)
107 {
108 int num = SkipWhiteSpacesAndNonLetter(pattern, index);
109 if (num != index && formatPostfix != null)
110 {
111 formatPostfix = null;
112 }
113 index = num;
115 while (index < pattern.Length)
116 {
117 char c = pattern[index];
118 switch (c)
119 {
120 case '\'':
121 break;
122 case '\\':
123 index++;
124 if (index < pattern.Length)
125 {
126 stringBuilder.Append(pattern[index]);
127 index++;
128 }
129 continue;
130 default:
131 if (char.IsWhiteSpace(c))
132 {
134 if (formatPostfix != null)
135 {
136 formatPostfix = null;
137 }
138 stringBuilder.Length = 0;
139 index++;
140 }
141 else
142 {
143 stringBuilder.Append(c);
144 index++;
145 }
146 continue;
147 }
149 index++;
150 break;
151 }
152 return index;
153 }
154
155 internal static int ScanRepeatChar(string pattern, char ch, int index, out int count)
156 {
157 count = 1;
158 while (++index < pattern.Length && pattern[index] == ch)
159 {
160 count++;
161 }
162 return index;
163 }
164
165 internal void AddIgnorableSymbols(string text)
166 {
167 if (m_dateWords == null)
168 {
170 }
171 string item = "\ue001" + text;
173 {
175 }
176 }
177
178 internal void ScanDateWord(string pattern)
179 {
181 int num = 0;
182 while (num < pattern.Length)
183 {
184 char c = pattern[num];
185 int count;
186 switch (c)
187 {
188 case '\'':
189 num = AddDateWords(pattern, num + 1, null);
190 break;
191 case 'M':
192 num = ScanRepeatChar(pattern, 'M', num, out count);
193 if (count >= 4 && num < pattern.Length && pattern[num] == '\'')
194 {
195 num = AddDateWords(pattern, num + 1, "MMMM");
196 }
197 _ymdFlags |= FoundDatePattern.FoundMonthPatternFlag;
198 break;
199 case 'y':
200 {
201 num = ScanRepeatChar(pattern, 'y', num, out var _);
202 _ymdFlags |= FoundDatePattern.FoundYearPatternFlag;
203 break;
204 }
205 case 'd':
206 num = ScanRepeatChar(pattern, 'd', num, out count);
207 if (count <= 2)
208 {
209 _ymdFlags |= FoundDatePattern.FoundDayPatternFlag;
210 }
211 break;
212 case '\\':
213 num += 2;
214 break;
215 case '.':
216 if (_ymdFlags == FoundDatePattern.FoundYMDPatternFlag)
217 {
220 }
221 num++;
222 break;
223 default:
224 if (_ymdFlags == FoundDatePattern.FoundYMDPatternFlag && !char.IsWhiteSpace(c))
225 {
227 }
228 num++;
229 break;
230 }
231 }
232 }
233
235 {
236 string[] allDateTimePatterns = dtfi.GetAllDateTimePatterns('D');
237 for (int i = 0; i < allDateTimePatterns.Length; i++)
238 {
240 }
241 allDateTimePatterns = dtfi.GetAllDateTimePatterns('d');
242 for (int i = 0; i < allDateTimePatterns.Length; i++)
243 {
245 }
246 allDateTimePatterns = dtfi.GetAllDateTimePatterns('y');
247 for (int i = 0; i < allDateTimePatterns.Length; i++)
248 {
250 }
251 ScanDateWord(dtfi.MonthDayPattern);
252 allDateTimePatterns = dtfi.GetAllDateTimePatterns('T');
253 for (int i = 0; i < allDateTimePatterns.Length; i++)
254 {
256 }
257 allDateTimePatterns = dtfi.GetAllDateTimePatterns('t');
258 for (int i = 0; i < allDateTimePatterns.Length; i++)
259 {
261 }
262 string[] array = null;
263 if (m_dateWords != null && m_dateWords.Count > 0)
264 {
265 array = new string[m_dateWords.Count];
266 for (int i = 0; i < m_dateWords.Count; i++)
267 {
268 array[i] = m_dateWords[i];
269 }
270 }
271 return array;
272 }
273
274 internal static FORMATFLAGS GetFormatFlagGenitiveMonth(string[] monthNames, string[] genitveMonthNames, string[] abbrevMonthNames, string[] genetiveAbbrevMonthNames)
275 {
277 {
278 return FORMATFLAGS.None;
279 }
280 return FORMATFLAGS.UseGenitiveMonth;
281 }
282
289
290 internal static FORMATFLAGS GetFormatFlagUseSpaceInDayNames(string[] dayNames, string[] abbrevDayNames)
291 {
293 {
294 return FORMATFLAGS.None;
295 }
296 return FORMATFLAGS.UseSpacesInDayNames;
297 }
298
300 {
301 if (calID != 8)
302 {
303 return FORMATFLAGS.None;
304 }
305 return (FORMATFLAGS)10;
306 }
307
308 private static bool EqualStringArrays(string[] array1, string[] array2)
309 {
310 if (array1 == array2)
311 {
312 return true;
313 }
314 if (array1.Length != array2.Length)
315 {
316 return false;
317 }
318 for (int i = 0; i < array1.Length; i++)
319 {
320 if (array1[i] != array2[i])
321 {
322 return false;
323 }
324 }
325 return true;
326 }
327
328 private static bool ArrayElementsHaveSpace(string[] array)
329 {
330 for (int i = 0; i < array.Length; i++)
331 {
332 for (int j = 0; j < array[i].Length; j++)
333 {
334 if (char.IsWhiteSpace(array[i][j]))
335 {
336 return true;
337 }
338 }
339 }
340 return false;
341 }
342
343 private static bool ArrayElementsBeginWithDigit(string[] array)
344 {
345 for (int i = 0; i < array.Length; i++)
346 {
347 if (array[i].Length <= 0 || array[i][0] < '0' || array[i][0] > '9')
348 {
349 continue;
350 }
351 int j;
352 for (j = 1; j < array[i].Length && array[i][j] >= '0' && array[i][j] <= '9'; j++)
353 {
354 }
355 if (j == array[i].Length)
356 {
357 return false;
358 }
359 if (j == array[i].Length - 1)
360 {
361 char c = array[i][j];
362 if (c == '月' || c == '월')
363 {
364 return false;
365 }
366 }
367 if (j == array[i].Length - 4 && array[i][j] == '\'' && array[i][j + 1] == ' ' && array[i][j + 2] == '月' && array[i][j + 3] == '\'')
368 {
369 return false;
370 }
371 return true;
372 }
373 return false;
374 }
375}
static FORMATFLAGS GetFormatFlagUseSpaceInDayNames(string[] dayNames, string[] abbrevDayNames)
static bool EqualStringArrays(string[] array1, string[] array2)
static FORMATFLAGS GetFormatFlagUseSpaceInMonthNames(string[] monthNames, string[] genitveMonthNames, string[] abbrevMonthNames, string[] genetiveAbbrevMonthNames)
static int ScanRepeatChar(string pattern, char ch, int index, out int count)
static FORMATFLAGS GetFormatFlagGenitiveMonth(string[] monthNames, string[] genitveMonthNames, string[] abbrevMonthNames, string[] genetiveAbbrevMonthNames)
void AddDateWordOrPostfix(string formatPostfix, string str)
static int SkipWhiteSpacesAndNonLetter(string pattern, int currentIndex)
int AddDateWords(string pattern, int index, string formatPostfix)