Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
MaskedTextProvider.cs
Go to the documentation of this file.
7using System.Text;
8
10
13{
14 private enum CaseConversion
15 {
16 None,
17 ToLower,
19 }
20
21 [Flags]
22 private enum CharType
23 {
24 EditOptional = 1,
25 EditRequired = 2,
26 Separator = 4,
27 Literal = 8,
28 Modifier = 0x10
29 }
30
31 private sealed class CharDescriptor
32 {
33 public int MaskPosition;
34
36
38
39 public bool IsAssigned;
40
46
47 public override string ToString()
48 {
49 return string.Format(CultureInfo.InvariantCulture, "MaskPosition[{0}] <CaseConversion.{1}><CharType.{2}><IsAssigned: {3}", MaskPosition, CaseConversion, CharType, IsAssigned);
50 }
51 }
52
53 private static readonly int s_ASCII_ONLY = BitVector32.CreateMask();
54
56
58
60
62
64
66
68
70
72
73 private int _requiredCharCount;
74
75 private int _requiredEditChars;
76
77 private int _optionalEditChars;
78
79 private char _passwordChar;
80
81 private char _promptChar;
82
84
86
87 public int AssignedEditPositionCount { get; private set; }
88
90
91 public CultureInfo Culture { get; }
92
93 public static char DefaultPasswordChar => '*';
94
96
98 {
99 get
100 {
101 List<int> list = new List<int>();
102 int num = 0;
104 {
105 if (IsEditPosition(item))
106 {
107 list.Add(num);
108 }
109 num++;
110 }
111 return ((IEnumerable)list).GetEnumerator();
112 }
113 }
114
115 public bool IncludeLiterals
116 {
117 get
118 {
120 }
121 set
122 {
124 }
125 }
126
127 public bool IncludePrompt
128 {
129 get
130 {
132 }
133 set
134 {
136 }
137 }
138
140
141 public bool IsPassword
142 {
143 get
144 {
145 return _passwordChar != '\0';
146 }
147 set
148 {
149 if (IsPassword != value)
150 {
152 }
153 }
154 }
155
156 public static int InvalidIndex => -1;
157
159
160 public int Length => _testString.Length;
161
162 public string Mask { get; }
163
165
167
168 public char PasswordChar
169 {
170 get
171 {
172 return _passwordChar;
173 }
174 set
175 {
176 if (value == _promptChar)
177 {
179 }
180 if (!IsValidPasswordChar(value) && value != 0)
181 {
183 }
184 if (value != _passwordChar)
185 {
187 }
188 }
189 }
190
191 public char PromptChar
192 {
193 get
194 {
195 return _promptChar;
196 }
197 set
198 {
199 if (value == _passwordChar)
200 {
202 }
204 {
206 }
207 if (value == _promptChar)
208 {
209 return;
210 }
212 for (int i = 0; i < _testString.Length; i++)
213 {
215 if (IsEditPosition(i) && !charDescriptor.IsAssigned)
216 {
218 }
219 }
220 }
221 }
222
223 public bool ResetOnPrompt
224 {
225 get
226 {
228 }
229 set
230 {
232 }
233 }
234
235 public bool ResetOnSpace
236 {
237 get
238 {
239 return _flagState[s_SKIP_SPACE];
240 }
241 set
242 {
244 }
245 }
246
247 public bool SkipLiterals
248 {
249 get
250 {
252 }
253 set
254 {
256 }
257 }
258
259 public char this[int index]
260 {
261 get
262 {
264 {
266 }
267 return _testString[index];
268 }
269 }
270
273 {
274 }
275
278 {
279 }
280
285
290
295
300
302 {
303 if (string.IsNullOrEmpty(mask))
304 {
306 }
307 foreach (char c in mask)
308 {
309 if (!IsPrintableChar(c))
310 {
312 }
313 }
314 if (culture == null)
315 {
317 }
318 _flagState = default(BitVector32);
319 Mask = mask;
322 if (culture.IsNeutralCulture)
323 {
325 foreach (CultureInfo cultureInfo in cultures)
326 {
327 if (culture.Equals(cultureInfo.Parent))
328 {
330 break;
331 }
332 }
333 if (Culture == null)
334 {
336 }
337 }
338 else
339 {
341 }
342 if (!Culture.IsReadOnly)
343 {
345 }
351 _flagState[s_SKIP_SPACE] = true;
353 Initialize();
354 }
355
356 [MemberNotNull("_testString")]
357 [MemberNotNull("_stringDescriptor")]
358 private void Initialize()
359 {
363 bool flag = false;
364 int num = 0;
365 CharType charType = CharType.Literal;
366 string text = string.Empty;
367 for (int i = 0; i < Mask.Length; i++)
368 {
369 char c = Mask[i];
370 if (!flag)
371 {
372 switch (c)
373 {
374 case '.':
375 text = Culture.NumberFormat.NumberDecimalSeparator;
376 charType = CharType.Separator;
377 break;
378 case ',':
379 text = Culture.NumberFormat.NumberGroupSeparator;
380 charType = CharType.Separator;
381 break;
382 case ':':
383 text = Culture.DateTimeFormat.TimeSeparator;
384 charType = CharType.Separator;
385 break;
386 case '/':
387 text = Culture.DateTimeFormat.DateSeparator;
388 charType = CharType.Separator;
389 break;
390 case '$':
391 text = Culture.NumberFormat.CurrencySymbol;
392 charType = CharType.Separator;
393 break;
394 case '<':
396 continue;
397 case '>':
399 continue;
400 case '|':
402 continue;
403 case '\\':
404 flag = true;
405 charType = CharType.Literal;
406 continue;
407 case '&':
408 case '0':
409 case 'A':
410 case 'L':
412 c = _promptChar;
413 charType = CharType.EditRequired;
414 break;
415 case '#':
416 case '9':
417 case '?':
418 case 'C':
419 case 'a':
421 c = _promptChar;
422 charType = CharType.EditOptional;
423 break;
424 default:
425 charType = CharType.Literal;
426 break;
427 }
428 }
429 else
430 {
431 flag = false;
432 }
435 {
436 charDescriptor.CaseConversion = caseConversion;
437 }
438 if (charType != CharType.Separator)
439 {
440 text = c.ToString();
441 }
442 string text2 = text;
443 foreach (char value in text2)
444 {
447 num++;
448 }
449 }
450 _testString.Capacity = _testString.Length;
451 }
452
453 [UnsupportedOSPlatform("browser")]
454 public object Clone()
455 {
456 Type type = GetType();
459 {
461 }
462 else
463 {
464 object[] args = new object[6] { Mask, Culture, AllowPromptAsInput, PromptChar, PasswordChar, AsciiOnly };
466 }
467 maskedTextProvider.ResetOnPrompt = false;
468 maskedTextProvider.ResetOnSpace = false;
469 maskedTextProvider.SkipLiterals = false;
470 for (int i = 0; i < _testString.Length; i++)
471 {
474 {
475 maskedTextProvider.Replace(_testString[i], i);
476 }
477 }
478 maskedTextProvider.ResetOnPrompt = ResetOnPrompt;
479 maskedTextProvider.ResetOnSpace = ResetOnSpace;
480 maskedTextProvider.SkipLiterals = SkipLiterals;
481 maskedTextProvider.IncludeLiterals = IncludeLiterals;
482 maskedTextProvider.IncludePrompt = IncludePrompt;
483 return maskedTextProvider;
484 }
485
486 public bool Add(char input)
487 {
488 int testPosition;
491 }
492
494 {
497 {
499 resultHint = MaskedTextResultHint.UnavailableEditPosition;
500 return false;
501 }
504 if (testPosition == -1)
505 {
506 resultHint = MaskedTextResultHint.UnavailableEditPosition;
508 return false;
509 }
511 {
512 return false;
513 }
514 return true;
515 }
516
517 public bool Add(string input)
518 {
519 int testPosition;
522 }
523
525 {
526 if (input == null)
527 {
528 throw new ArgumentNullException("input");
529 }
531 if (input.Length == 0)
532 {
534 return true;
535 }
537 }
538
539 public void Clear()
540 {
541 Clear(out var _);
542 }
543
545 {
547 {
549 return;
550 }
552 for (int i = 0; i < _testString.Length; i++)
553 {
554 ResetChar(i);
555 }
556 }
557
558 public int FindAssignedEditPositionFrom(int position, bool direction)
559 {
561 {
562 return -1;
563 }
564 int startPosition;
565 int endPosition;
566 if (direction)
567 {
568 startPosition = position;
569 endPosition = _testString.Length - 1;
570 }
571 else
572 {
573 startPosition = 0;
574 endPosition = position;
575 }
577 }
578
579 public int FindAssignedEditPositionInRange(int startPosition, int endPosition, bool direction)
580 {
582 {
583 return -1;
584 }
586 }
587
588 public int FindEditPositionFrom(int position, bool direction)
589 {
590 int startPosition;
591 int endPosition;
592 if (direction)
593 {
594 startPosition = position;
595 endPosition = _testString.Length - 1;
596 }
597 else
598 {
599 startPosition = 0;
600 endPosition = position;
601 }
603 }
604
605 public int FindEditPositionInRange(int startPosition, int endPosition, bool direction)
606 {
607 CharType charTypeFlags = CharType.EditOptional | CharType.EditRequired;
609 }
610
611 private int FindEditPositionInRange(int startPosition, int endPosition, bool direction, byte assignedStatus)
612 {
613 do
614 {
616 if (num == -1)
617 {
618 break;
619 }
621 switch (assignedStatus)
622 {
623 case 1:
624 if (!charDescriptor.IsAssigned)
625 {
626 return num;
627 }
628 break;
629 case 2:
630 if (charDescriptor.IsAssigned)
631 {
632 return num;
633 }
634 break;
635 default:
636 return num;
637 }
638 if (direction)
639 {
641 }
642 else
643 {
644 endPosition--;
645 }
646 }
647 while (startPosition <= endPosition);
648 return -1;
649 }
650
651 public int FindNonEditPositionFrom(int position, bool direction)
652 {
653 int startPosition;
654 int endPosition;
655 if (direction)
656 {
657 startPosition = position;
658 endPosition = _testString.Length - 1;
659 }
660 else
661 {
662 startPosition = 0;
663 endPosition = position;
664 }
666 }
667
668 public int FindNonEditPositionInRange(int startPosition, int endPosition, bool direction)
669 {
670 CharType charTypeFlags = CharType.Separator | CharType.Literal;
672 }
673
675 {
676 if (startPosition < 0)
677 {
678 startPosition = 0;
679 }
681 {
682 endPosition = _testString.Length - 1;
683 }
685 {
686 return -1;
687 }
688 while (startPosition <= endPosition)
689 {
690 int num = (direction ? startPosition++ : endPosition--);
692 if ((charDescriptor.CharType & charTypeFlags) == charDescriptor.CharType)
693 {
694 return num;
695 }
696 }
697 return -1;
698 }
699
700 public int FindUnassignedEditPositionFrom(int position, bool direction)
701 {
702 int startPosition;
703 int endPosition;
704 if (direction)
705 {
706 startPosition = position;
707 endPosition = _testString.Length - 1;
708 }
709 else
710 {
711 startPosition = 0;
712 endPosition = position;
713 }
715 }
716
718 {
719 int num;
720 while (true)
721 {
723 if (num == -1)
724 {
725 return -1;
726 }
728 if (!charDescriptor.IsAssigned)
729 {
730 break;
731 }
732 if (direction)
733 {
735 }
736 else
737 {
738 endPosition--;
739 }
740 }
741 return num;
742 }
743
745 {
746 return hint > MaskedTextResultHint.Unknown;
747 }
748
749 public bool InsertAt(char input, int position)
750 {
752 {
753 return false;
754 }
755 return InsertAt(input.ToString(), position);
756 }
757
758 public bool InsertAt(char input, int position, out int testPosition, out MaskedTextResultHint resultHint)
759 {
760 return InsertAt(input.ToString(), position, out testPosition, out resultHint);
761 }
762
763 public bool InsertAt(string input, int position)
764 {
765 int testPosition;
767 return InsertAt(input, position, out testPosition, out resultHint);
768 }
769
770 public bool InsertAt(string input, int position, out int testPosition, out MaskedTextResultHint resultHint)
771 {
772 if (input == null)
773 {
774 throw new ArgumentNullException("input");
775 }
777 {
778 testPosition = position;
779 resultHint = MaskedTextResultHint.PositionOutOfRange;
780 return false;
781 }
782 return InsertAtInt(input, position, out testPosition, out resultHint, testOnly: false);
783 }
784
785 private bool InsertAtInt(string input, int position, out int testPosition, out MaskedTextResultHint resultHint, bool testOnly)
786 {
787 if (input.Length == 0)
788 {
789 testPosition = position;
791 return true;
792 }
793 if (!TestString(input, position, out testPosition, out resultHint))
794 {
795 return false;
796 }
797 int num = FindEditPositionFrom(position, direction: true);
798 bool flag = FindAssignedEditPositionInRange(num, testPosition, direction: true) != -1;
800 if (flag && testPosition == _testString.Length - 1)
801 {
802 resultHint = MaskedTextResultHint.UnavailableEditPosition;
804 return false;
805 }
806 int num2 = FindEditPositionFrom(testPosition + 1, direction: true);
807 if (flag)
808 {
810 while (true)
811 {
812 if (num2 == -1)
813 {
814 resultHint = MaskedTextResultHint.UnavailableEditPosition;
816 return false;
817 }
819 if (charDescriptor.IsAssigned && !TestChar(_testString[num], num2, out resultHint2))
820 {
823 return false;
824 }
825 if (num == lastAssignedPosition)
826 {
827 break;
828 }
829 num = FindEditPositionFrom(num + 1, direction: true);
830 num2 = FindEditPositionFrom(num2 + 1, direction: true);
831 }
833 {
835 }
836 }
837 if (testOnly)
838 {
839 return true;
840 }
841 if (flag)
842 {
843 while (num >= position)
844 {
846 if (charDescriptor2.IsAssigned)
847 {
848 SetChar(_testString[num], num2);
849 }
850 else
851 {
853 }
854 num2 = FindEditPositionFrom(num2 - 1, direction: false);
855 num = FindEditPositionFrom(num - 1, direction: false);
856 }
857 }
858 SetString(input, position);
859 return true;
860 }
861
862 private static bool IsAscii(char c)
863 {
864 if (c >= '!')
865 {
866 return c <= '~';
867 }
868 return false;
869 }
870
871 private static bool IsAciiAlphanumeric(char c)
872 {
873 if ((c < '0' || c > '9') && (c < 'A' || c > 'Z'))
874 {
875 if (c >= 'a')
876 {
877 return c <= 'z';
878 }
879 return false;
880 }
881 return true;
882 }
883
884 private static bool IsAlphanumeric(char c)
885 {
886 if (!char.IsLetter(c))
887 {
888 return char.IsDigit(c);
889 }
890 return true;
891 }
892
893 private static bool IsAsciiLetter(char c)
894 {
895 if (c < 'A' || c > 'Z')
896 {
897 if (c >= 'a')
898 {
899 return c <= 'z';
900 }
901 return false;
902 }
903 return true;
904 }
905
906 public bool IsAvailablePosition(int position)
907 {
909 {
910 return false;
911 }
914 {
915 return !charDescriptor.IsAssigned;
916 }
917 return false;
918 }
919
920 public bool IsEditPosition(int position)
921 {
923 {
924 return false;
925 }
928 }
929
931 {
932 if (charDescriptor.CharType != CharType.EditRequired)
933 {
934 return charDescriptor.CharType == CharType.EditOptional;
935 }
936 return true;
937 }
938
940 {
941 if (charDescriptor.CharType != CharType.Literal)
942 {
943 return charDescriptor.CharType == CharType.Separator;
944 }
945 return true;
946 }
947
948 private static bool IsPrintableChar(char c)
949 {
950 if (!char.IsLetterOrDigit(c) && !char.IsPunctuation(c) && !char.IsSymbol(c))
951 {
952 return c == ' ';
953 }
954 return true;
955 }
956
957 public static bool IsValidInputChar(char c)
958 {
959 return IsPrintableChar(c);
960 }
961
962 public static bool IsValidMaskChar(char c)
963 {
964 return IsPrintableChar(c);
965 }
966
967 public static bool IsValidPasswordChar(char c)
968 {
969 if (!IsPrintableChar(c))
970 {
971 return c == '\0';
972 }
973 return true;
974 }
975
976 public bool Remove()
977 {
978 int testPosition;
981 }
982
984 {
986 if (lastAssignedPosition == -1)
987 {
988 testPosition = 0;
990 return true;
991 }
995 return true;
996 }
997
998 public bool RemoveAt(int position)
999 {
1000 return RemoveAt(position, position);
1001 }
1002
1009
1011 {
1013 {
1015 resultHint = MaskedTextResultHint.PositionOutOfRange;
1016 return false;
1017 }
1019 {
1021 resultHint = MaskedTextResultHint.PositionOutOfRange;
1022 return false;
1023 }
1025 }
1026
1028 {
1030 int num = FindEditPositionInRange(startPosition, endPosition, direction: true);
1032 if (num == -1 || num > lastAssignedPosition)
1033 {
1035 return true;
1036 }
1038 bool flag = endPosition < lastAssignedPosition;
1039 if (FindAssignedEditPositionInRange(startPosition, endPosition, direction: true) != -1)
1040 {
1042 }
1043 if (flag)
1044 {
1045 int num2 = FindEditPositionFrom(endPosition + 1, direction: true);
1046 int num3 = num2;
1047 startPosition = num;
1048 while (true)
1049 {
1050 char c = _testString[num2];
1052 if ((c != PromptChar || charDescriptor.IsAssigned) && !TestChar(c, num, out var resultHint2))
1053 {
1055 testPosition = num;
1056 return false;
1057 }
1059 {
1060 break;
1061 }
1062 num2 = FindEditPositionFrom(num2 + 1, direction: true);
1063 num = FindEditPositionFrom(num + 1, direction: true);
1064 }
1065 if (MaskedTextResultHint.SideEffect > resultHint)
1066 {
1067 resultHint = MaskedTextResultHint.SideEffect;
1068 }
1069 if (testOnly)
1070 {
1071 return true;
1072 }
1073 num2 = num3;
1074 num = startPosition;
1075 while (true)
1076 {
1077 char c2 = _testString[num2];
1079 if (c2 == PromptChar && !charDescriptor2.IsAssigned)
1080 {
1081 ResetChar(num);
1082 }
1083 else
1084 {
1085 SetChar(c2, num);
1086 ResetChar(num2);
1087 }
1089 {
1090 break;
1091 }
1092 num2 = FindEditPositionFrom(num2 + 1, direction: true);
1093 num = FindEditPositionFrom(num + 1, direction: true);
1094 }
1095 startPosition = num + 1;
1096 }
1098 {
1100 }
1101 return true;
1102 }
1103
1104 public bool Replace(char input, int position)
1105 {
1106 int testPosition;
1108 return Replace(input, position, out testPosition, out resultHint);
1109 }
1110
1111 public bool Replace(char input, int position, out int testPosition, out MaskedTextResultHint resultHint)
1112 {
1114 {
1115 testPosition = position;
1116 resultHint = MaskedTextResultHint.PositionOutOfRange;
1117 return false;
1118 }
1119 testPosition = position;
1121 {
1123 }
1124 if (testPosition == -1)
1125 {
1126 resultHint = MaskedTextResultHint.UnavailableEditPosition;
1127 testPosition = position;
1128 return false;
1129 }
1131 {
1132 return false;
1133 }
1134 return true;
1135 }
1136
1138 {
1140 {
1142 resultHint = MaskedTextResultHint.PositionOutOfRange;
1143 return false;
1144 }
1146 {
1148 resultHint = MaskedTextResultHint.PositionOutOfRange;
1149 return false;
1150 }
1152 {
1155 }
1157 }
1158
1159 public bool Replace(string input, int position)
1160 {
1161 int testPosition;
1163 return Replace(input, position, out testPosition, out resultHint);
1164 }
1165
1166 public bool Replace(string input, int position, out int testPosition, out MaskedTextResultHint resultHint)
1167 {
1168 if (input == null)
1169 {
1170 throw new ArgumentNullException("input");
1171 }
1173 {
1174 testPosition = position;
1175 resultHint = MaskedTextResultHint.PositionOutOfRange;
1176 return false;
1177 }
1178 if (input.Length == 0)
1179 {
1180 return RemoveAt(position, position, out testPosition, out resultHint);
1181 }
1183 {
1184 return false;
1185 }
1186 return true;
1187 }
1188
1190 {
1191 if (input == null)
1192 {
1193 throw new ArgumentNullException("input");
1194 }
1196 {
1198 resultHint = MaskedTextResultHint.PositionOutOfRange;
1199 return false;
1200 }
1202 {
1204 resultHint = MaskedTextResultHint.PositionOutOfRange;
1205 return false;
1206 }
1207 if (input.Length == 0)
1208 {
1210 }
1212 {
1213 return false;
1214 }
1216 {
1219 {
1221 {
1224 return false;
1225 }
1227 {
1228 resultHint = MaskedTextResultHint.SideEffect;
1229 }
1230 }
1231 else if (testPosition > endPosition)
1232 {
1234 int position = testPosition + 1;
1235 int position2 = endPosition + 1;
1236 while (true)
1237 {
1238 position2 = FindEditPositionFrom(position2, direction: true);
1239 position = FindEditPositionFrom(position, direction: true);
1240 if (position == -1)
1241 {
1243 resultHint = MaskedTextResultHint.UnavailableEditPosition;
1244 return false;
1245 }
1246 if (!TestChar(_testString[position2], position, out resultHint2))
1247 {
1248 testPosition = position;
1250 return false;
1251 }
1253 {
1255 }
1257 {
1258 break;
1259 }
1260 position2++;
1261 position++;
1262 }
1263 while (position > testPosition)
1264 {
1265 SetChar(_testString[position2], position);
1266 position2 = FindEditPositionFrom(position2 - 1, direction: false);
1267 position = FindEditPositionFrom(position - 1, direction: false);
1268 }
1269 }
1270 }
1272 return true;
1273 }
1274
1275 private void ResetChar(int testPosition)
1276 {
1278 if (IsEditPosition(testPosition) && charDescriptor.IsAssigned)
1279 {
1280 charDescriptor.IsAssigned = false;
1283 if (charDescriptor.CharType == CharType.EditRequired)
1284 {
1286 }
1287 }
1288 }
1289
1291 {
1293 if (startPosition != -1)
1294 {
1296 while (startPosition <= endPosition)
1297 {
1300 startPosition++;
1301 }
1302 }
1303 }
1304
1305 public bool Set(string input)
1306 {
1307 int testPosition;
1310 }
1311
1313 {
1314 if (input == null)
1315 {
1316 throw new ArgumentNullException("input");
1317 }
1319 testPosition = 0;
1320 if (input.Length == 0)
1321 {
1323 return true;
1324 }
1326 {
1327 return false;
1328 }
1329 int num = FindAssignedEditPositionFrom(testPosition + 1, direction: true);
1330 if (num != -1)
1331 {
1332 ResetString(num, _testString.Length - 1);
1333 }
1334 return true;
1335 }
1336
1337 private void SetChar(char input, int position)
1338 {
1340 SetChar(input, position, charDescriptor);
1341 }
1342
1343 private void SetChar(char input, int position, CharDescriptor charDescriptor)
1344 {
1346 if (TestEscapeChar(input, position, charDescriptor))
1347 {
1348 ResetChar(position);
1349 return;
1350 }
1351 if (char.IsLetter(input))
1352 {
1353 if (char.IsUpper(input))
1354 {
1355 if (charDescriptor.CaseConversion == CaseConversion.ToLower)
1356 {
1357 input = Culture.TextInfo.ToLower(input);
1358 }
1359 }
1360 else if (charDescriptor.CaseConversion == CaseConversion.ToUpper)
1361 {
1362 input = Culture.TextInfo.ToUpper(input);
1363 }
1364 }
1365 _testString[position] = input;
1366 if (!charDescriptor.IsAssigned)
1367 {
1368 charDescriptor.IsAssigned = true;
1370 if (charDescriptor.CharType == CharType.EditRequired)
1371 {
1373 }
1374 }
1375 }
1376
1377 private void SetString(string input, int testPosition)
1378 {
1379 foreach (char input2 in input)
1380 {
1382 {
1384 }
1386 testPosition++;
1387 }
1388 }
1389
1390 private bool TestChar(char input, int position, out MaskedTextResultHint resultHint)
1391 {
1392 if (!IsPrintableChar(input))
1393 {
1394 resultHint = MaskedTextResultHint.InvalidInput;
1395 return false;
1396 }
1399 {
1400 if (SkipLiterals && input == _testString[position])
1401 {
1402 resultHint = MaskedTextResultHint.CharacterEscaped;
1403 return true;
1404 }
1405 resultHint = MaskedTextResultHint.NonEditPosition;
1406 return false;
1407 }
1408 if (input == _promptChar)
1409 {
1410 if (ResetOnPrompt)
1411 {
1412 if (IsEditPosition(charDescriptor) && charDescriptor.IsAssigned)
1413 {
1414 resultHint = MaskedTextResultHint.SideEffect;
1415 }
1416 else
1417 {
1418 resultHint = MaskedTextResultHint.CharacterEscaped;
1419 }
1420 return true;
1421 }
1422 if (!AllowPromptAsInput)
1423 {
1424 resultHint = MaskedTextResultHint.PromptCharNotAllowed;
1425 return false;
1426 }
1427 }
1428 if (input == ' ' && ResetOnSpace)
1429 {
1430 if (IsEditPosition(charDescriptor) && charDescriptor.IsAssigned)
1431 {
1432 resultHint = MaskedTextResultHint.SideEffect;
1433 }
1434 else
1435 {
1436 resultHint = MaskedTextResultHint.CharacterEscaped;
1437 }
1438 return true;
1439 }
1440 switch (Mask[charDescriptor.MaskPosition])
1441 {
1442 case '#':
1443 if (!char.IsDigit(input) && input != '-' && input != '+' && input != ' ')
1444 {
1445 resultHint = MaskedTextResultHint.DigitExpected;
1446 return false;
1447 }
1448 break;
1449 case '0':
1450 if (!char.IsDigit(input))
1451 {
1452 resultHint = MaskedTextResultHint.DigitExpected;
1453 return false;
1454 }
1455 break;
1456 case '9':
1457 if (!char.IsDigit(input) && input != ' ')
1458 {
1459 resultHint = MaskedTextResultHint.DigitExpected;
1460 return false;
1461 }
1462 break;
1463 case 'L':
1464 if (!char.IsLetter(input))
1465 {
1466 resultHint = MaskedTextResultHint.LetterExpected;
1467 return false;
1468 }
1469 if (!IsAsciiLetter(input) && AsciiOnly)
1470 {
1471 resultHint = MaskedTextResultHint.AsciiCharacterExpected;
1472 return false;
1473 }
1474 break;
1475 case '?':
1476 if (!char.IsLetter(input) && input != ' ')
1477 {
1478 resultHint = MaskedTextResultHint.LetterExpected;
1479 return false;
1480 }
1481 if (!IsAsciiLetter(input) && AsciiOnly)
1482 {
1483 resultHint = MaskedTextResultHint.AsciiCharacterExpected;
1484 return false;
1485 }
1486 break;
1487 case '&':
1488 if (!IsAscii(input) && AsciiOnly)
1489 {
1490 resultHint = MaskedTextResultHint.AsciiCharacterExpected;
1491 return false;
1492 }
1493 break;
1494 case 'C':
1495 if (!IsAscii(input) && AsciiOnly && input != ' ')
1496 {
1497 resultHint = MaskedTextResultHint.AsciiCharacterExpected;
1498 return false;
1499 }
1500 break;
1501 case 'A':
1502 if (!IsAlphanumeric(input))
1503 {
1504 resultHint = MaskedTextResultHint.AlphanumericCharacterExpected;
1505 return false;
1506 }
1508 {
1509 resultHint = MaskedTextResultHint.AsciiCharacterExpected;
1510 return false;
1511 }
1512 break;
1513 case 'a':
1514 if (!IsAlphanumeric(input) && input != ' ')
1515 {
1516 resultHint = MaskedTextResultHint.AlphanumericCharacterExpected;
1517 return false;
1518 }
1520 {
1521 resultHint = MaskedTextResultHint.AsciiCharacterExpected;
1522 return false;
1523 }
1524 break;
1525 }
1526 if (input == _testString[position] && charDescriptor.IsAssigned)
1527 {
1529 }
1530 else
1531 {
1533 }
1534 return true;
1535 }
1536
1537 private bool TestEscapeChar(char input, int position)
1538 {
1540 return TestEscapeChar(input, position, charDex);
1541 }
1542
1543 private bool TestEscapeChar(char input, int position, CharDescriptor charDex)
1544 {
1546 {
1547 if (SkipLiterals)
1548 {
1549 return input == _testString[position];
1550 }
1551 return false;
1552 }
1553 if ((ResetOnPrompt && input == _promptChar) || (ResetOnSpace && input == ' '))
1554 {
1555 return true;
1556 }
1557 return false;
1558 }
1559
1560 private bool TestSetChar(char input, int position, out MaskedTextResultHint resultHint)
1561 {
1562 if (TestChar(input, position, out resultHint))
1563 {
1564 if (resultHint == MaskedTextResultHint.Success || resultHint == MaskedTextResultHint.SideEffect)
1565 {
1566 SetChar(input, position);
1567 }
1568 return true;
1569 }
1570 return false;
1571 }
1572
1573 private bool TestSetString(string input, int position, out int testPosition, out MaskedTextResultHint resultHint)
1574 {
1575 if (TestString(input, position, out testPosition, out resultHint))
1576 {
1577 SetString(input, position);
1578 return true;
1579 }
1580 return false;
1581 }
1582
1583 private bool TestString(string input, int position, out int testPosition, out MaskedTextResultHint resultHint)
1584 {
1586 testPosition = position;
1587 if (input.Length == 0)
1588 {
1589 return true;
1590 }
1592 foreach (char input2 in input)
1593 {
1595 {
1596 resultHint = MaskedTextResultHint.UnavailableEditPosition;
1597 return false;
1598 }
1600 {
1602 if (testPosition == -1)
1603 {
1605 resultHint = MaskedTextResultHint.UnavailableEditPosition;
1606 return false;
1607 }
1608 }
1610 {
1612 return false;
1613 }
1614 if (resultHint2 > resultHint)
1615 {
1617 }
1618 testPosition++;
1619 }
1620 testPosition--;
1621 return true;
1622 }
1623
1624 public string ToDisplayString()
1625 {
1627 {
1628 return _testString.ToString();
1629 }
1631 for (int i = 0; i < _testString.Length; i++)
1632 {
1635 }
1636 return stringBuilder.ToString();
1637 }
1638
1639 public override string ToString()
1640 {
1642 }
1643
1648
1649 public string ToString(int startPosition, int length)
1650 {
1652 }
1653
1658
1659 public string ToString(bool includePrompt, bool includeLiterals)
1660 {
1662 }
1663
1668
1670 {
1671 if (length <= 0)
1672 {
1673 return string.Empty;
1674 }
1675 if (startPosition < 0)
1676 {
1677 startPosition = 0;
1678 }
1680 {
1681 return string.Empty;
1682 }
1683 int num = _testString.Length - startPosition;
1684 if (length > num)
1685 {
1686 length = num;
1687 }
1689 {
1691 }
1693 int num2 = startPosition + length - 1;
1694 if (!includePrompt)
1695 {
1697 int num4 = FindAssignedEditPositionInRange((num3 == InvalidIndex) ? startPosition : num3, num2, direction: false);
1698 num2 = ((num4 != InvalidIndex) ? num4 : num3);
1699 if (num2 == InvalidIndex)
1700 {
1701 return string.Empty;
1702 }
1703 }
1704 for (int i = startPosition; i <= num2; i++)
1705 {
1706 char value = _testString[i];
1708 switch (charDescriptor.CharType)
1709 {
1710 case CharType.EditOptional:
1711 case CharType.EditRequired:
1712 if (charDescriptor.IsAssigned)
1713 {
1715 {
1717 continue;
1718 }
1719 }
1720 else if (!includePrompt)
1721 {
1722 stringBuilder.Append(' ');
1723 continue;
1724 }
1725 break;
1726 case CharType.Separator:
1727 case CharType.Literal:
1728 if (!includeLiterals)
1729 {
1730 continue;
1731 }
1732 break;
1733 }
1734 stringBuilder.Append(value);
1735 }
1736 return stringBuilder.ToString();
1737 }
1738
1739 public bool VerifyChar(char input, int position, out MaskedTextResultHint hint)
1740 {
1741 hint = MaskedTextResultHint.NoEffect;
1743 {
1744 hint = MaskedTextResultHint.PositionOutOfRange;
1745 return false;
1746 }
1747 return TestChar(input, position, out hint);
1748 }
1749
1750 public bool VerifyEscapeChar(char input, int position)
1751 {
1753 {
1754 return false;
1755 }
1756 return TestEscapeChar(input, position);
1757 }
1758
1759 public bool VerifyString(string input)
1760 {
1761 int testPosition;
1764 }
1765
1767 {
1768 testPosition = 0;
1769 if (input == null || input.Length == 0)
1770 {
1772 return true;
1773 }
1775 }
1776}
static ? object CreateInstance([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors|DynamicallyAccessedMemberTypes.NonPublicConstructors)] Type type, BindingFlags bindingAttr, Binder? binder, object?[]? args, CultureInfo? culture)
Definition Activator.cs:17
void Add(TKey key, TValue value)
int FindPositionInRange(int startPosition, int endPosition, bool direction, CharType charTypeFlags)
bool VerifyString(string input, out int testPosition, out MaskedTextResultHint resultHint)
static bool IsEditPosition(CharDescriptor charDescriptor)
bool Replace(string input, int position, out int testPosition, out MaskedTextResultHint resultHint)
MaskedTextProvider(string mask, bool restrictToAscii)
void SetString(string input, int testPosition)
bool VerifyEscapeChar(char input, int position)
MaskedTextProvider(string mask, CultureInfo? culture, char passwordChar, bool allowPromptAsInput)
bool Replace(char input, int position, out int testPosition, out MaskedTextResultHint resultHint)
int FindAssignedEditPositionFrom(int position, bool direction)
bool RemoveAtInt(int startPosition, int endPosition, out int testPosition, out MaskedTextResultHint resultHint, bool testOnly)
bool Replace(string input, int startPosition, int endPosition, out int testPosition, out MaskedTextResultHint resultHint)
MaskedTextProvider(string mask, CultureInfo? culture)
bool TestEscapeChar(char input, int position, CharDescriptor charDex)
static bool GetOperationResultFromHint(MaskedTextResultHint hint)
bool RemoveAt(int startPosition, int endPosition)
int FindEditPositionInRange(int startPosition, int endPosition, bool direction, byte assignedStatus)
bool Set(string input, out int testPosition, out MaskedTextResultHint resultHint)
bool VerifyChar(char input, int position, out MaskedTextResultHint hint)
bool Add(string input, out int testPosition, out MaskedTextResultHint resultHint)
int FindUnassignedEditPositionFrom(int position, bool direction)
bool Remove(out int testPosition, out MaskedTextResultHint resultHint)
bool TestSetChar(char input, int position, out MaskedTextResultHint resultHint)
bool InsertAt(string input, int position)
string ToString(bool ignorePasswordChar, int startPosition, int length)
static bool IsLiteralPosition(CharDescriptor charDescriptor)
bool Replace(string input, int position)
bool TestEscapeChar(char input, int position)
bool TestString(string input, int position, out int testPosition, out MaskedTextResultHint resultHint)
bool InsertAt(char input, int position, out int testPosition, out MaskedTextResultHint resultHint)
MaskedTextProvider(string mask, CultureInfo? culture, bool restrictToAscii)
int FindEditPositionInRange(int startPosition, int endPosition, bool direction)
bool InsertAtInt(string input, int position, out int testPosition, out MaskedTextResultHint resultHint, bool testOnly)
bool Replace(char input, int startPosition, int endPosition, out int testPosition, out MaskedTextResultHint resultHint)
bool TestChar(char input, int position, out MaskedTextResultHint resultHint)
bool InsertAt(char input, int position)
bool Add(char input, out int testPosition, out MaskedTextResultHint resultHint)
void ResetString(int startPosition, int endPosition)
string ToString(bool ignorePasswordChar)
string ToString(bool ignorePasswordChar, bool includePrompt, bool includeLiterals, int startPosition, int length)
string ToString(bool includePrompt, bool includeLiterals, int startPosition, int length)
bool TestSetString(string input, int position, out int testPosition, out MaskedTextResultHint resultHint)
MaskedTextProvider(string mask, CultureInfo? culture, bool allowPromptAsInput, char promptChar, char passwordChar, bool restrictToAscii)
int FindAssignedEditPositionInRange(int startPosition, int endPosition, bool direction)
string ToString(int startPosition, int length)
MaskedTextProvider(string mask, char passwordChar, bool allowPromptAsInput)
string ToString(bool includePrompt, bool includeLiterals)
int FindNonEditPositionFrom(int position, bool direction)
int FindNonEditPositionInRange(int startPosition, int endPosition, bool direction)
bool InsertAt(string input, int position, out int testPosition, out MaskedTextResultHint resultHint)
int FindEditPositionFrom(int position, bool direction)
void Clear(out MaskedTextResultHint resultHint)
void SetChar(char input, int position, CharDescriptor charDescriptor)
bool RemoveAt(int startPosition, int endPosition, out int testPosition, out MaskedTextResultHint resultHint)
int FindUnassignedEditPositionInRange(int startPosition, int endPosition, bool direction)
static CultureInfo ReadOnly(CultureInfo ci)
static CultureInfo[] GetCultures(CultureTypes types)
virtual DateTimeFormatInfo DateTimeFormat
static CultureInfo CurrentCulture
static CultureInfo InvariantCulture
virtual NumberFormatInfo NumberFormat
static string MaskedTextProviderPasswordAndPromptCharError
Definition SR.cs:90
static string MaskedTextProviderMaskNullOrEmpty
Definition SR.cs:94
static string MaskedTextProviderInvalidCharError
Definition SR.cs:92
static string MaskedTextProviderMaskInvalidChar
Definition SR.cs:96
Definition SR.cs:7
override string ToString()
StringBuilder Append(char value, int repeatCount)