From fb421a1e27c38c20126356044b75e879a3245ed8 Mon Sep 17 00:00:00 2001 From: Soreepeong Date: Wed, 28 Aug 2024 01:13:11 +0900 Subject: [PATCH] Fix hexadecimal digit lookup table A is 0x41, not 0x40. --- src/Lumina/Text/Parse/MacroStringParser.cs | 25 +++++++++++++--------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/Lumina/Text/Parse/MacroStringParser.cs b/src/Lumina/Text/Parse/MacroStringParser.cs index de398b21..9cf510d5 100644 --- a/src/Lumina/Text/Parse/MacroStringParser.cs +++ b/src/Lumina/Text/Parse/MacroStringParser.cs @@ -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;