From 289555c082f913ef56e5bc6afdd7147c8f6c521d Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Wed, 9 Sep 2015 19:22:41 +0100 Subject: [PATCH] fix #1908 --- src/core/StringBuilder.hpp | 14 ++++++++++++++ src/localisation/LanguagePack.cpp | 11 ++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/core/StringBuilder.hpp b/src/core/StringBuilder.hpp index b96c1cbe89..db83790573 100644 --- a/src/core/StringBuilder.hpp +++ b/src/core/StringBuilder.hpp @@ -41,13 +41,27 @@ public: */ void Append(const utf8 *text) { int textLength = strlen(text); + Append(text, textLength); + } + /** + * 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. + */ + void Append(const utf8 *text, int textLength) { EnsureCapacity(_length + textLength + 1); Memory::Copy(_buffer + _length, text, textLength); _length += textLength; _buffer[_length] = 0; } + /** + * Appends the string of a given StringBuilder to the current string. + */ + void Append(const StringBuilder *sb) { + Append(sb->GetBuffer(), sb->GetLength()); + } + /** * Clears the current string, but preserves the allocated memory for another string. */ diff --git a/src/localisation/LanguagePack.cpp b/src/localisation/LanguagePack.cpp index cacc01da88..dd980d382e 100644 --- a/src/localisation/LanguagePack.cpp +++ b/src/localisation/LanguagePack.cpp @@ -445,7 +445,7 @@ void LanguagePack::ParseString(IStringReader *reader) } } - _stringDataSB.Append(sb.GetBuffer()); + _stringDataSB.Append(&sb); } bool LanguagePack::ParseToken(IStringReader *reader, uint32 *token) @@ -469,5 +469,14 @@ bool LanguagePack::ParseToken(IStringReader *reader, uint32 *token) const utf8 *tokenName = sb.GetBuffer(); *token = format_get_code(tokenName); + + // Handle explicit byte values + if (*token == 0) { + int number; + if (sscanf(tokenName, "%d", &number) == 1) { + *token = Math::Clamp(0, number, 255); + } + } + return true; }