mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2025-12-18 05:22:42 +01:00
fix #1982
This commit is contained in:
@@ -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
|
* 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.
|
* 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) {
|
void Append(const utf8 *text, int textLength) {
|
||||||
EnsureCapacity(_length + textLength + 1);
|
EnsureCapacity(_length + textLength + 1);
|
||||||
|
|||||||
@@ -415,11 +415,16 @@ void LanguagePack::ParseString(IStringReader *reader)
|
|||||||
while (reader->TryPeek(&codepoint) && !IsNewLine(codepoint)) {
|
while (reader->TryPeek(&codepoint) && !IsNewLine(codepoint)) {
|
||||||
if (codepoint == '{') {
|
if (codepoint == '{') {
|
||||||
uint32 token;
|
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
|
// Syntax error or unknown token, ignore line entirely
|
||||||
return;
|
return;
|
||||||
} else {
|
|
||||||
sb.Append((int)token);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
reader->Skip();
|
reader->Skip();
|
||||||
@@ -451,7 +456,7 @@ void LanguagePack::ParseString(IStringReader *reader)
|
|||||||
_stringDataSB.Append(&sb);
|
_stringDataSB.Append(&sb);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LanguagePack::ParseToken(IStringReader *reader, uint32 *token)
|
bool LanguagePack::ParseToken(IStringReader *reader, uint32 *token, bool *isByte)
|
||||||
{
|
{
|
||||||
auto sb = StringBuilder();
|
auto sb = StringBuilder();
|
||||||
int codepoint;
|
int codepoint;
|
||||||
@@ -472,12 +477,14 @@ bool LanguagePack::ParseToken(IStringReader *reader, uint32 *token)
|
|||||||
|
|
||||||
const utf8 *tokenName = sb.GetBuffer();
|
const utf8 *tokenName = sb.GetBuffer();
|
||||||
*token = format_get_code(tokenName);
|
*token = format_get_code(tokenName);
|
||||||
|
*isByte = false;
|
||||||
|
|
||||||
// Handle explicit byte values
|
// Handle explicit byte values
|
||||||
if (*token == 0) {
|
if (*token == 0) {
|
||||||
int number;
|
int number;
|
||||||
if (sscanf(tokenName, "%d", &number) == 1) {
|
if (sscanf(tokenName, "%d", &number) == 1) {
|
||||||
*token = Math::Clamp(0, number, 255);
|
*token = Math::Clamp(0, number, 255);
|
||||||
|
*isByte = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -73,5 +73,5 @@ private:
|
|||||||
void ParseGroupScenario(IStringReader *reader);
|
void ParseGroupScenario(IStringReader *reader);
|
||||||
void ParseString(IStringReader *reader);
|
void ParseString(IStringReader *reader);
|
||||||
|
|
||||||
bool ParseToken(IStringReader *reader, uint32 *token);
|
bool ParseToken(IStringReader *reader, uint32 *token, bool *isByte);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user