Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
BMPEncoding.cs
Go to the documentation of this file.
1namespace System.Formats.Asn1;
2
3internal sealed class BMPEncoding : SpanBasedEncoding
4{
5 protected override int GetBytes(ReadOnlySpan<char> chars, Span<byte> bytes, bool write)
6 {
7 if (chars.IsEmpty)
8 {
9 return 0;
10 }
11 int num = 0;
12 for (int i = 0; i < chars.Length; i++)
13 {
14 char c = chars[i];
15 if (char.IsSurrogate(c))
16 {
17 base.EncoderFallback.CreateFallbackBuffer().Fallback(c, i);
18 throw new InvalidOperationException();
19 }
20 ushort num2 = c;
21 if (write)
22 {
23 bytes[num + 1] = (byte)num2;
24 bytes[num] = (byte)(num2 >> 8);
25 }
26 num += 2;
27 }
28 return num;
29 }
30
31 protected override int GetChars(ReadOnlySpan<byte> bytes, Span<char> chars, bool write)
32 {
33 if (bytes.IsEmpty)
34 {
35 return 0;
36 }
37 if (bytes.Length % 2 != 0)
38 {
39 base.DecoderFallback.CreateFallbackBuffer().Fallback(bytes.Slice(bytes.Length - 1).ToArray(), bytes.Length - 1);
40 throw new InvalidOperationException();
41 }
42 int num = 0;
43 for (int i = 0; i < bytes.Length; i += 2)
44 {
45 int num2 = (bytes[i] << 8) | bytes[i + 1];
46 char c = (char)num2;
47 if (char.IsSurrogate(c))
48 {
49 base.DecoderFallback.CreateFallbackBuffer().Fallback(bytes.Slice(i, 2).ToArray(), i);
50 throw new InvalidOperationException();
51 }
52 if (write)
53 {
54 chars[num] = c;
55 }
56 num++;
57 }
58 return num;
59 }
60
61 public override int GetMaxByteCount(int charCount)
62 {
63 return checked(charCount * 2);
64 }
65
66 public override int GetMaxCharCount(int byteCount)
67 {
68 return byteCount / 2;
69 }
70}
override int GetMaxByteCount(int charCount)
override int GetBytes(ReadOnlySpan< char > chars, Span< byte > bytes, bool write)
Definition BMPEncoding.cs:5
override int GetMaxCharCount(int byteCount)
override int GetChars(ReadOnlySpan< byte > bytes, Span< char > chars, bool write)