Terraria
v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
RestrictedAsciiStringEncoding.cs
Go to the documentation of this file.
1
using
System.Collections.Generic
;
2
3
namespace
System.Formats.Asn1
;
4
5
internal
abstract
class
RestrictedAsciiStringEncoding
:
SpanBasedEncoding
6
{
7
private
readonly
bool
[]
_isAllowed
;
8
9
protected
RestrictedAsciiStringEncoding
(
byte
minCharAllowed
,
byte
maxCharAllowed
)
10
{
11
bool
[]
array
=
new
bool
[128];
12
for
(
byte
b
=
minCharAllowed
;
b
<=
maxCharAllowed
;
b
++)
13
{
14
array
[
b
] =
true
;
15
}
16
_isAllowed
=
array
;
17
}
18
19
protected
RestrictedAsciiStringEncoding
(
IEnumerable<char>
allowedChars
)
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
}
30
_isAllowed
=
array
;
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
}
System.ArgumentOutOfRangeException
Definition
ArgumentOutOfRangeException.cs:9
System.Collections.Generic.Dictionary
Definition
Dictionary.cs:14
System.Formats.Asn1.RestrictedAsciiStringEncoding._isAllowed
readonly bool[] _isAllowed
Definition
RestrictedAsciiStringEncoding.cs:7
System.Formats.Asn1.RestrictedAsciiStringEncoding.GetChars
override int GetChars(ReadOnlySpan< byte > bytes, Span< char > chars, bool write)
Definition
RestrictedAsciiStringEncoding.cs:65
System.Formats.Asn1.RestrictedAsciiStringEncoding.RestrictedAsciiStringEncoding
RestrictedAsciiStringEncoding(byte minCharAllowed, byte maxCharAllowed)
Definition
RestrictedAsciiStringEncoding.cs:9
System.Formats.Asn1.RestrictedAsciiStringEncoding.GetBytes
override int GetBytes(ReadOnlySpan< char > chars, Span< byte > bytes, bool write)
Definition
RestrictedAsciiStringEncoding.cs:43
System.Formats.Asn1.RestrictedAsciiStringEncoding.GetMaxByteCount
override int GetMaxByteCount(int charCount)
Definition
RestrictedAsciiStringEncoding.cs:33
System.Formats.Asn1.RestrictedAsciiStringEncoding.GetMaxCharCount
override int GetMaxCharCount(int byteCount)
Definition
RestrictedAsciiStringEncoding.cs:38
System.Formats.Asn1.RestrictedAsciiStringEncoding.RestrictedAsciiStringEncoding
RestrictedAsciiStringEncoding(IEnumerable< char > allowedChars)
Definition
RestrictedAsciiStringEncoding.cs:19
System.Formats.Asn1.RestrictedAsciiStringEncoding
Definition
RestrictedAsciiStringEncoding.cs:6
System.Formats.Asn1.SpanBasedEncoding
Definition
SpanBasedEncoding.cs:6
System.InvalidOperationException
Definition
InvalidOperationException.cs:9
System.Collections.Generic
Definition
IHashKeyCollection.cs:1
System.Formats.Asn1
Definition
Asn1Tag.cs:3
System.ExceptionArgument.bytes
@ bytes
System.ExceptionArgument.charCount
@ charCount
System.ExceptionArgument.byteCount
@ byteCount
System.ExceptionArgument.chars
@ chars
System.ExceptionArgument.array
@ array
source
System.Formats.Asn1
System.Formats.Asn1
RestrictedAsciiStringEncoding.cs
Generated by
1.10.0