Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ EscapeUnescapeIri()

static unsafe string System.IriHelper.EscapeUnescapeIri ( char * pInput,
int start,
int end,
UriComponents component )
inlinestaticpackage

Definition at line 84 of file IriHelper.cs.

85 {
86 int num = end - start;
87 System.Text.ValueStringBuilder valueStringBuilder;
88 if (num <= 512)
89 {
90 Span<char> initialBuffer = stackalloc char[512];
91 valueStringBuilder = new System.Text.ValueStringBuilder(initialBuffer);
92 }
93 else
94 {
95 valueStringBuilder = new System.Text.ValueStringBuilder(num);
96 }
97 System.Text.ValueStringBuilder to = valueStringBuilder;
98 Span<byte> destination = stackalloc byte[4];
99 for (int i = start; i < end; i++)
100 {
101 char c = pInput[i];
102 if (c == '%')
103 {
104 if (end - i > 2)
105 {
106 c = UriHelper.DecodeHexChars(pInput[i + 1], pInput[i + 2]);
107 if (c == '\uffff' || c == '%' || CheckIsReserved(c, component) || UriHelper.IsNotSafeForUnescape(c))
108 {
109 to.Append(pInput[i++]);
110 to.Append(pInput[i++]);
111 to.Append(pInput[i]);
112 }
113 else if (c <= '\u007f')
114 {
115 to.Append(c);
116 i += 2;
117 }
118 else
119 {
120 int num2 = PercentEncodingHelper.UnescapePercentEncodedUTF8Sequence(pInput + i, end - i, ref to, component == UriComponents.Query, iriParsing: true);
121 i += num2 - 1;
122 }
123 }
124 else
125 {
126 to.Append(pInput[i]);
127 }
128 }
129 else if (c > '\u007f')
130 {
131 bool isSurrogatePair = false;
132 char c2 = '\0';
133 bool flag;
134 if (char.IsHighSurrogate(c) && i + 1 < end)
135 {
136 c2 = pInput[i + 1];
137 flag = CheckIriUnicodeRange(c, c2, out isSurrogatePair, component == UriComponents.Query);
138 }
139 else
140 {
141 flag = CheckIriUnicodeRange(c, component == UriComponents.Query);
142 }
143 if (flag)
144 {
145 to.Append(c);
146 if (isSurrogatePair)
147 {
148 to.Append(c2);
149 }
150 }
151 else
152 {
153 Rune result;
154 if (isSurrogatePair)
155 {
156 result = new Rune(c, c2);
157 }
158 else if (!Rune.TryCreate(c, out result))
159 {
160 result = Rune.ReplacementChar;
161 }
162 Span<byte> span = destination[..result.EncodeToUtf8(destination)];
163 Span<byte> span2 = span;
164 for (int j = 0; j < span2.Length; j++)
165 {
166 byte b = span2[j];
167 UriHelper.EscapeAsciiChar(b, ref to);
168 }
169 }
170 if (isSurrogatePair)
171 {
172 i++;
173 }
174 }
175 else
176 {
177 to.Append(pInput[i]);
178 }
179 }
180 return to.ToString();
181 }
static bool CheckIsReserved(char ch, UriComponents component)
Definition IriHelper.cs:71
static bool CheckIriUnicodeRange(char unicode, bool isQuery)
Definition IriHelper.cs:8
static Rune ReplacementChar
Definition Rune.cs:53
static bool TryCreate(char ch, out Rune result)
Definition Rune.cs:511

References System.Text.ValueStringBuilder.Append(), System.IriHelper.CheckIriUnicodeRange(), System.IriHelper.CheckIsReserved(), System.UriHelper.DecodeHexChars(), System.destination, System.Text.Rune.EncodeToUtf8(), System.UriHelper.EscapeAsciiChar(), System.UriHelper.IsNotSafeForUnescape(), System.Span< T >.Length, System.Text.Rune.ReplacementChar, System.start, System.Text.ValueStringBuilder.ToString(), System.Text.Rune.TryCreate(), and System.PercentEncodingHelper.UnescapePercentEncodedUTF8Sequence().

Referenced by System.Uri.CheckAuthorityHelper(), and System.Uri.EscapeUnescapeIri().