Skip to content

Commit 6cbf781

Browse files
authored
Merge pull request #90 from Soreepeong/fix/hex-lookup-table
Fix hexadecimal digit lookup table
2 parents 1164c8b + fb421a1 commit 6cbf781

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

src/Lumina/Text/Parse/MacroStringParser.cs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,26 @@ internal readonly ref struct MacroStringParser
1111
{
1212
// Map from ascii code to supposed number.
1313
// -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;
2416

2517
private readonly ReadOnlySpan< byte > _macroString;
2618
private readonly MacroStringParseOptions _parseOptions;
2719
private readonly SeStringBuilder _builder;
2820

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+
2934
internal MacroStringParser( ReadOnlySpan< byte > macroString, SeStringBuilder builder, MacroStringParseOptions parseOptions )
3035
{
3136
_macroString = macroString;

0 commit comments

Comments
 (0)