Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
RestrictedAsciiStringEncoding.cs
Go to the documentation of this file.
2
3namespace System.Formats.Asn1;
4
6{
7 private readonly bool[] _isAllowed;
8
10 {
11 bool[] array = new bool[128];
12 for (byte b = minCharAllowed; b <= maxCharAllowed; b++)
13 {
14 array[b] = true;
15 }
17 }
18
20 {
21 bool[] array = new bool[127];
22 foreach (char allowedChar in allowedChars)
23 {
24 if (allowedChar >= array.Length)
25 {
26 throw new ArgumentOutOfRangeException("allowedChars");
27 }
28 array[(uint)allowedChar] = true;
29 }
31 }
32
33 public override int GetMaxByteCount(int charCount)
34 {
35 return charCount;
36 }
37
38 public override int GetMaxCharCount(int byteCount)
39 {
40 return byteCount;
41 }
42
43 protected override int GetBytes(ReadOnlySpan<char> chars, Span<byte> bytes, bool write)
44 {
45 if (chars.IsEmpty)
46 {
47 return 0;
48 }
49 for (int i = 0; i < chars.Length; i++)
50 {
51 char c = chars[i];
52 if ((uint)c >= (uint)_isAllowed.Length || !_isAllowed[(uint)c])
53 {
54 base.EncoderFallback.CreateFallbackBuffer().Fallback(c, i);
55 throw new InvalidOperationException();
56 }
57 if (write)
58 {
59 bytes[i] = (byte)c;
60 }
61 }
62 return chars.Length;
63 }
64
65 protected override int GetChars(ReadOnlySpan<byte> bytes, Span<char> chars, bool write)
66 {
67 if (bytes.IsEmpty)
68 {
69 return 0;
70 }
71 for (int i = 0; i < bytes.Length; i++)
72 {
73 byte b = bytes[i];
74 if ((uint)b >= (uint)_isAllowed.Length || !_isAllowed[b])
75 {
76 base.DecoderFallback.CreateFallbackBuffer().Fallback(new byte[1] { b }, i);
77 throw new InvalidOperationException();
78 }
79 if (write)
80 {
81 chars[i] = (char)b;
82 }
83 }
84 return bytes.Length;
85 }
86}
override int GetChars(ReadOnlySpan< byte > bytes, Span< char > chars, bool write)
RestrictedAsciiStringEncoding(byte minCharAllowed, byte maxCharAllowed)
override int GetBytes(ReadOnlySpan< char > chars, Span< byte > bytes, bool write)