Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
BinHexEncoding.cs
Go to the documentation of this file.
1namespace System.Text;
2
3internal sealed class BinHexEncoding : Encoding
4{
5 public override int GetMaxByteCount(int charCount)
6 {
7 if (charCount < 0)
8 {
10 }
11 if (charCount % 2 != 0)
12 {
14 }
15 return charCount / 2;
16 }
17
18 public override int GetByteCount(char[] chars, int index, int count)
19 {
20 return GetMaxByteCount(count);
21 }
22
23 public override int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex)
24 {
25 if (chars == null)
26 {
27 throw new ArgumentNullException("chars");
28 }
29 if (charIndex < 0)
30 {
32 }
33 if (charIndex > chars.Length)
34 {
36 }
37 if (charCount < 0)
38 {
40 }
41 if (charCount > chars.Length - charIndex)
42 {
44 }
45 if (bytes == null)
46 {
47 throw new ArgumentNullException("bytes");
48 }
49 if (byteIndex < 0)
50 {
52 }
53 if (byteIndex > bytes.Length)
54 {
56 }
58 if (byteCount < 0 || byteCount > bytes.Length - byteIndex)
59 {
60 throw new ArgumentException(System.SR.XmlArrayTooSmall, "bytes");
61 }
62 if (charCount > 0 && !System.HexConverter.TryDecodeFromUtf16(chars.AsSpan(charIndex, charCount), bytes.AsSpan(byteIndex, byteCount), out var charsProcessed))
63 {
64 int num = charsProcessed + charIndex;
65 throw new FormatException(System.SR.Format(System.SR.XmlInvalidBinHexSequence, new string(chars, num, 2), num));
66 }
67 return byteCount;
68 }
69
70 public override int GetMaxCharCount(int byteCount)
71 {
72 if (byteCount < 0 || byteCount > 1073741823)
73 {
74 throw new ArgumentOutOfRangeException("byteCount", System.SR.Format(System.SR.ValueMustBeInRange, 0, 1073741823));
75 }
76 return byteCount * 2;
77 }
78
79 public override int GetCharCount(byte[] bytes, int index, int count)
80 {
81 return GetMaxCharCount(count);
82 }
83
84 public override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex)
85 {
86 if (bytes == null)
87 {
88 throw new ArgumentNullException("bytes");
89 }
90 if (byteIndex < 0)
91 {
93 }
94 if (byteIndex > bytes.Length)
95 {
97 }
98 if (byteCount < 0)
99 {
101 }
102 if (byteCount > bytes.Length - byteIndex)
103 {
105 }
107 if (chars == null)
108 {
109 throw new ArgumentNullException("chars");
110 }
111 if (charIndex < 0)
112 {
114 }
115 if (charIndex > chars.Length)
116 {
118 }
119 if (charCount < 0 || charCount > chars.Length - charIndex)
120 {
121 throw new ArgumentException(System.SR.XmlArrayTooSmall, "chars");
122 }
123 if (byteCount > 0)
124 {
126 }
127 return charCount;
128 }
129}
static void EncodeToUtf16(ReadOnlySpan< byte > bytes, Span< char > chars, Casing casing=Casing.Upper)
static bool TryDecodeFromUtf16(ReadOnlySpan< char > chars, Span< byte > bytes)
static string ValueMustBeInRange
Definition SR.cs:326
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string ValueMustBeNonNegative
Definition SR.cs:296
static string XmlInvalidBinHexSequence
Definition SR.cs:338
static string SizeExceedsRemainingBufferSpace
Definition SR.cs:324
static string XmlInvalidBinHexLength
Definition SR.cs:336
static string OffsetExceedsBufferSize
Definition SR.cs:322
static string XmlArrayTooSmall
Definition SR.cs:348
Definition SR.cs:7
override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex)
override int GetMaxByteCount(int charCount)
override int GetCharCount(byte[] bytes, int index, int count)
override int GetByteCount(char[] chars, int index, int count)
override int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex)
override int GetMaxCharCount(int byteCount)