1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-15 19:13:07 +01:00

Use std::string for objects

This commit is contained in:
Ted John
2017-12-05 12:55:33 +00:00
committed by Michael Steenbeek
parent eed00ea363
commit 31e112cf3b
13 changed files with 104 additions and 111 deletions

View File

@@ -40,9 +40,9 @@ static const uint8 RCT2ToOpenRCT2LanguageId[] =
LANGUAGE_PORTUGUESE_BR,
};
static bool StringIsBlank(utf8 * str)
static bool StringIsBlank(const utf8 * str)
{
for (utf8 * ch = str; *ch != '\0'; ch++)
for (auto ch = str; *ch != '\0'; ch++)
{
if (!isblank(*ch))
{
@@ -52,14 +52,6 @@ static bool StringIsBlank(utf8 * str)
return true;
}
StringTable::~StringTable()
{
for (auto entry : _strings)
{
Memory::Free(entry.Text);
}
}
void StringTable::Read(IReadObjectContext * context, IStream * stream, uint8 id)
{
try
@@ -96,7 +88,7 @@ void StringTable::Read(IReadObjectContext * context, IStream * stream, uint8 id)
Sort();
}
const utf8 * StringTable::GetString(uint8 id) const
std::string StringTable::GetString(uint8 id) const
{
for (auto &string : _strings)
{
@@ -108,6 +100,15 @@ const utf8 * StringTable::GetString(uint8 id) const
return nullptr;
}
void StringTable::SetString(uint8 id, uint8 language, const std::string &text)
{
StringTableEntry entry;
entry.Id = id;
entry.LanguageId = language;
entry.Text = String::Duplicate(text);
_strings.push_back(entry);
}
void StringTable::Sort()
{
std::sort(_strings.begin(), _strings.end(), [](const StringTableEntry &a, const StringTableEntry &b) -> bool
@@ -116,7 +117,7 @@ void StringTable::Sort()
{
if (a.LanguageId == b.LanguageId)
{
return _strcmpi(a.Text, b.Text) < 0;
return String::Compare(a.Text, b.Text, true) < 0;
}
if (a.LanguageId == gCurrentLanguage)