diff --git a/src/core/StringBuilder.hpp b/src/core/StringBuilder.hpp index 19f69f3c1c..3c39617a4a 100644 --- a/src/core/StringBuilder.hpp +++ b/src/core/StringBuilder.hpp @@ -47,6 +47,8 @@ public: /** * Appends the given string of the given length to the current string. Essentially used to ignore null terminators or copy * the data faster as the length is already known. + * @param text Pointer to the UTF-8 text to append. + * @param textLength Number of bytes to copy. (Can be used to append single bytes rather than codepoints) */ void Append(const utf8 *text, int textLength) { EnsureCapacity(_length + textLength + 1); diff --git a/src/localisation/LanguagePack.cpp b/src/localisation/LanguagePack.cpp index f50ffb3519..b4386129ed 100644 --- a/src/localisation/LanguagePack.cpp +++ b/src/localisation/LanguagePack.cpp @@ -415,11 +415,16 @@ void LanguagePack::ParseString(IStringReader *reader) while (reader->TryPeek(&codepoint) && !IsNewLine(codepoint)) { if (codepoint == '{') { uint32 token; - if (!ParseToken(reader, &token)) { + bool isByte; + if (ParseToken(reader, &token, &isByte)) { + if (isByte) { + sb.Append((const utf8*)&token, 1); + } else { + sb.Append((int)token); + } + } else { // Syntax error or unknown token, ignore line entirely return; - } else { - sb.Append((int)token); } } else { reader->Skip(); @@ -451,7 +456,7 @@ void LanguagePack::ParseString(IStringReader *reader) _stringDataSB.Append(&sb); } -bool LanguagePack::ParseToken(IStringReader *reader, uint32 *token) +bool LanguagePack::ParseToken(IStringReader *reader, uint32 *token, bool *isByte) { auto sb = StringBuilder(); int codepoint; @@ -472,12 +477,14 @@ bool LanguagePack::ParseToken(IStringReader *reader, uint32 *token) const utf8 *tokenName = sb.GetBuffer(); *token = format_get_code(tokenName); + *isByte = false; // Handle explicit byte values if (*token == 0) { int number; if (sscanf(tokenName, "%d", &number) == 1) { *token = Math::Clamp(0, number, 255); + *isByte = true; } } diff --git a/src/localisation/LanguagePack.h b/src/localisation/LanguagePack.h index 56a3479184..871b689401 100644 --- a/src/localisation/LanguagePack.h +++ b/src/localisation/LanguagePack.h @@ -73,5 +73,5 @@ private: void ParseGroupScenario(IStringReader *reader); void ParseString(IStringReader *reader); - bool ParseToken(IStringReader *reader, uint32 *token); + bool ParseToken(IStringReader *reader, uint32 *token, bool *isByte); };