@@ -11,21 +11,26 @@ internal readonly ref struct MacroStringParser
11
11
{
12
12
// Map from ascii code to supposed number.
13
13
// -1 = invalid, -2 = ignore.
14
- private static readonly sbyte [ ] Digits =
15
- [
16
- - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 ,
17
- - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 ,
18
- - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 2 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , // _
19
- + 0 , + 1 , + 2 , + 3 , + 4 , + 5 , + 6 , + 7 , + 8 , + 9 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , // 0-9
20
- 10 , 11 , 12 , 13 , 14 , 15 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , // A-F
21
- - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 2 , // '
22
- 10 , 11 , 12 , 13 , 14 , 15 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , // a-f
23
- ] ;
14
+ // See the static constructor for initialization.
15
+ private static readonly sbyte [ ] Digits ;
24
16
25
17
private readonly ReadOnlySpan < byte > _macroString ;
26
18
private readonly MacroStringParseOptions _parseOptions ;
27
19
private readonly SeStringBuilder _builder ;
28
20
21
+ static MacroStringParser ( )
22
+ {
23
+ Digits = new sbyte [ 0x80 ] ;
24
+ Digits . AsSpan ( ) . Fill ( - 1 ) ;
25
+ Digits [ '_' ] = Digits [ '\' ' ] = - 2 ;
26
+ for ( var i = '0' ; i <= '9' ; i ++ )
27
+ Digits [ i ] = ( sbyte ) ( i - '0' ) ;
28
+ for ( var i = 'A' ; i <= 'F' ; i ++ )
29
+ Digits [ i ] = ( sbyte ) ( 10 + ( i - 'A' ) ) ;
30
+ for ( var i = 'a' ; i <= 'f' ; i ++ )
31
+ Digits [ i ] = ( sbyte ) ( 10 + ( i - 'a' ) ) ;
32
+ }
33
+
29
34
internal MacroStringParser ( ReadOnlySpan < byte > macroString , SeStringBuilder builder , MacroStringParseOptions parseOptions )
30
35
{
31
36
_macroString = macroString ;
0 commit comments