Skip to content

Commit

Permalink
Merge pull request #90 from Soreepeong/fix/hex-lookup-table
Browse files Browse the repository at this point in the history
Fix hexadecimal digit lookup table
  • Loading branch information
NotAdam authored Aug 28, 2024
2 parents 1164c8b + fb421a1 commit 6cbf781
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/Lumina/Text/Parse/MacroStringParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,26 @@ internal readonly ref struct MacroStringParser
{
// Map from ascii code to supposed number.
// -1 = invalid, -2 = ignore.
private static readonly sbyte[] Digits =
[
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -2, -1, -1, -1, -1, -1, -1, -1, -1, // _
+0, +1, +2, +3, +4, +5, +6, +7, +8, +9, -1, -1, -1, -1, -1, -1, // 0-9
10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // A-F
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -2, // '
10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // a-f
];
// See the static constructor for initialization.
private static readonly sbyte[] Digits;

private readonly ReadOnlySpan< byte > _macroString;
private readonly MacroStringParseOptions _parseOptions;
private readonly SeStringBuilder _builder;

static MacroStringParser()
{
Digits = new sbyte[0x80];
Digits.AsSpan().Fill(-1);
Digits['_'] = Digits['\''] = -2;
for (var i = '0'; i <= '9'; i++)
Digits[i] = (sbyte)(i - '0');
for (var i = 'A'; i <= 'F'; i++)
Digits[i] = (sbyte)(10 + (i - 'A'));
for (var i = 'a'; i <= 'f'; i++)
Digits[i] = (sbyte)(10 + (i - 'a'));
}

internal MacroStringParser( ReadOnlySpan< byte > macroString, SeStringBuilder builder, MacroStringParseOptions parseOptions )
{
_macroString = macroString;
Expand Down

0 comments on commit 6cbf781

Please sign in to comment.