Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
StringReaderWrapExtension.cs
Go to the documentation of this file.
3using System.IO;
4using System.Linq;
5using System.Text;
6
7namespace ReLogic.Text;
8
9internal static class StringReaderWrapExtension
10{
11 internal enum WrapScanMode
12 {
13 Space,
14 NewLine,
15 Word,
16 None
17 }
18
20 {
21 '!', '%', ')', ',', '.', ':', ';', '?', ']', '}',
22 '¢', '°', '·', '’', '"', '"', '†', '‡', '›', '℃',
23 '∶', '、', '。', '〃', '〆', '〕', '〗', '〞', '﹚', '﹜',
24 '!', '"', '%', ''', ')', ',', '.', ':', ';', '?',
25 '!', ']', '}', '~', ' ', '\n'
26 };
27
29 {
30 '$', '(', '£', '¥', '·', '‘', '"', '〈', '《', '「',
31 '『', '【', '〔', '〖', '〝', '﹙', '﹛', '$', '(', '.',
32 '[', '{', '£', '¥'
33 };
34
35 private static readonly CultureInfo[] SupportedCultures = new CultureInfo[9]
36 {
37 new CultureInfo("en-US"),
38 new CultureInfo("de-DE"),
39 new CultureInfo("it-IT"),
40 new CultureInfo("fr-FR"),
41 new CultureInfo("es-ES"),
42 new CultureInfo("ru-RU"),
43 new CultureInfo("zh-Hans"),
44 new CultureInfo("pt-BR"),
45 new CultureInfo("pl-PL")
46 };
47
48 private static readonly CultureInfo SimplifiedChinese = new CultureInfo("zh-Hans");
49
50 internal static bool IsCultureSupported(CultureInfo culture)
51 {
52 return SupportedCultures.Contains(culture);
53 }
54
55 internal static bool IsIgnoredCharacter(char character)
56 {
57 if (character < ' ')
58 {
59 return character != '\n';
60 }
61 return false;
62 }
63
64 internal static bool CanBreakBetween(char previousChar, char nextChar, CultureInfo culture)
65 {
66 if (culture.LCID == SimplifiedChinese.LCID)
67 {
69 {
71 }
72 return false;
73 }
74 return false;
75 }
76
78 {
80 {
81 return WrapScanMode.None;
82 }
83 return character switch
84 {
85 '\n' => WrapScanMode.NewLine,
86 ' ' => WrapScanMode.Space,
87 _ => WrapScanMode.Word,
88 };
89 }
90
91 internal static string ReadUntilBreakable(this StringReader reader, CultureInfo culture)
92 {
94 char c = (char)reader.Peek();
96 while (reader.Peek() > 0)
97 {
98 if (IsIgnoredCharacter((char)reader.Peek()))
99 {
100 reader.Read();
101 continue;
102 }
103 char previousChar = c;
104 c = (char)reader.Peek();
107 if (!stringBuilder.IsEmpty() && wrapScanMode2 != wrapScanMode)
108 {
109 return stringBuilder.ToString();
110 }
111 if (stringBuilder.IsEmpty())
112 {
113 stringBuilder.Append((char)reader.Read());
114 continue;
115 }
116 if (CanBreakBetween(previousChar, c, culture))
117 {
118 return stringBuilder.ToString();
119 }
120 stringBuilder.Append((char)reader.Read());
121 }
122 return stringBuilder.ToString();
123 }
124}
static bool CanBreakBetween(char previousChar, char nextChar, CultureInfo culture)
static WrapScanMode GetModeForCharacter(char character)
static readonly HashSet< char > InvalidCharactersForLineEnd
static readonly CultureInfo[] SupportedCultures
static bool IsCultureSupported(CultureInfo culture)
static string ReadUntilBreakable(this StringReader reader, CultureInfo culture)
static readonly HashSet< char > InvalidCharactersForLineStart
override int Read()
override int Peek()