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

◆ WriteUTF8()

static unsafe void System.Reflection.BlobUtilities.WriteUTF8 ( this byte[] buffer,
int start,
char * charPtr,
int charCount,
int byteCount,
bool allowUnpairedSurrogates )
inlinestatic

Definition at line 140 of file BlobUtilities.cs.

141 {
142 char* ptr = charPtr + charCount;
143 fixed (byte* ptr2 = &buffer[0])
144 {
145 byte* ptr3 = ptr2 + start;
146 if (byteCount == charCount)
147 {
148 while (charPtr < ptr)
149 {
150 *(ptr3++) = (byte)(*(charPtr++));
151 }
152 return;
153 }
154 while (charPtr < ptr)
155 {
156 char c = *(charPtr++);
157 if (c < '\u0080')
158 {
159 *(ptr3++) = (byte)c;
160 continue;
161 }
162 if (c < 'ࠀ')
163 {
164 *ptr3 = (byte)(((uint)((int)c >> 6) & 0x1Fu) | 0xC0u);
165 ptr3[1] = (byte)((c & 0x3Fu) | 0x80u);
166 ptr3 += 2;
167 continue;
168 }
169 if (IsSurrogateChar(c))
170 {
171 if (IsHighSurrogateChar(c) && charPtr < ptr && IsLowSurrogateChar(*charPtr))
172 {
173 int num = c;
174 int num2 = *(charPtr++);
175 int num3 = (num - 55296 << 10) + num2 - 56320 + 65536;
176 *ptr3 = (byte)(((uint)(num3 >> 18) & 7u) | 0xF0u);
177 ptr3[1] = (byte)(((uint)(num3 >> 12) & 0x3Fu) | 0x80u);
178 ptr3[2] = (byte)(((uint)(num3 >> 6) & 0x3Fu) | 0x80u);
179 ptr3[3] = (byte)(((uint)num3 & 0x3Fu) | 0x80u);
180 ptr3 += 4;
181 continue;
182 }
183 if (!allowUnpairedSurrogates)
184 {
185 c = '\ufffd';
186 }
187 }
188 *ptr3 = (byte)(((uint)((int)c >> 12) & 0xFu) | 0xE0u);
189 ptr3[1] = (byte)(((uint)((int)c >> 6) & 0x3Fu) | 0x80u);
190 ptr3[2] = (byte)((c & 0x3Fu) | 0x80u);
191 ptr3 += 3;
192 }
193 }
194 }
static bool IsLowSurrogateChar(int c)
static bool IsHighSurrogateChar(int c)
static bool IsSurrogateChar(int c)

References System.buffer, System.byteCount, System.charCount, System.Reflection.BlobUtilities.IsHighSurrogateChar(), System.Reflection.BlobUtilities.IsLowSurrogateChar(), System.Reflection.BlobUtilities.IsSurrogateChar(), and System.start.