diff --git a/src/d_main.h b/src/d_main.h index 05d818f14..bc8f54ada 100644 --- a/src/d_main.h +++ b/src/d_main.h @@ -160,7 +160,7 @@ public: int GetIWadFlags(unsigned int num) const { if (num < mIWadInfos.Size()) return mIWadInfos[num].flags; - else return false; + else return 0; } }; diff --git a/src/stringtable.cpp b/src/stringtable.cpp index 73f292d28..326aa2722 100644 --- a/src/stringtable.cpp +++ b/src/stringtable.cpp @@ -87,11 +87,11 @@ void FStringTable::LoadLanguage (int lumpnum) } if (len == 1 && sc.String[0] == '*') { - activeMaps.Push(MAKE_ID('*', 0, 0, 0)); + activeMaps.Push(global_table); } else if (len == 7 && stricmp (sc.String, "default") == 0) { - activeMaps.Push(MAKE_ID('*', '*', 0, 0)); + activeMaps.Push(default_table); } else { @@ -177,15 +177,15 @@ void FStringTable::UpdateLanguage() auto checkone = [&](uint32_t lang_id) { auto list = allStrings.CheckKey(lang_id); - if (list && currentLanguageSet.Find(list) == currentLanguageSet.Size()) - currentLanguageSet.Push(list); + if (list && currentLanguageSet.FindEx([&](const auto &element) { return element.first == lang_id; }) == currentLanguageSet.Size()) + currentLanguageSet.Push(std::make_pair(lang_id, list)); }; - checkone(MAKE_ID('*', '*', '*', 0)); - checkone(MAKE_ID('*', 0, 0, 0)); + checkone(dehacked_table); + checkone(global_table); checkone(LanguageID); checkone(LanguageID & MAKE_ID(0xff, 0xff, 0, 0)); - checkone(MAKE_ID('*', '*', 0, 0)); + checkone(default_table); } // Replace \ escape sequences in a string with the escaped characters. @@ -226,7 +226,7 @@ bool FStringTable::exists(const char *name) FName nm(name, true); if (nm != NAME_None) { - uint32_t defaultStrings[] = { MAKE_ID('*', '*', '*', 0), MAKE_ID('*', 0, 0, 0), MAKE_ID('*', '*', 0, 0) }; + uint32_t defaultStrings[] = { default_table, global_table, dehacked_table }; for (auto mapid : defaultStrings) { @@ -242,7 +242,7 @@ bool FStringTable::exists(const char *name) } // Finds a string by name and returns its value -const char *FStringTable::operator[] (const char *name) const +const char *FStringTable::GetString(const char *name, uint32_t *langtable) const { if (name == nullptr || *name == 0) { @@ -253,8 +253,12 @@ const char *FStringTable::operator[] (const char *name) const { for (auto map : currentLanguageSet) { - auto item = map->CheckKey(nm); - if (item) return item->GetChars(); + auto item = map.second->CheckKey(nm); + if (item) + { + if (langtable) *langtable = map.first; + return item->GetChars(); + } } } return nullptr; diff --git a/src/stringtable.h b/src/stringtable.h index 11416367c..97201a582 100644 --- a/src/stringtable.h +++ b/src/stringtable.h @@ -58,25 +58,36 @@ public: class FStringTable { public: + enum : uint32_t + { + default_table = MAKE_ID('*', '*', 0, 0), + global_table = MAKE_ID('*', 0, 0, 0), + dehacked_table = MAKE_ID('*', '*', '*', 0) + }; + using LangMap = TMap; void LoadStrings (); void UpdateLanguage(); - StringMap GetDefaultStrings() { return allStrings[MAKE_ID('*', '*', 0, 0)]; } // Dehacked needs these for comparison + StringMap GetDefaultStrings() { return allStrings[default_table]; } // Dehacked needs these for comparison void SetDehackedStrings(StringMap && map) { - allStrings.Insert(MAKE_ID('*', '*', '*', 0), map); + allStrings.Insert(dehacked_table, map); UpdateLanguage(); } - + + const char *GetString(const char *name, uint32_t *langtable) const; const char *operator() (const char *name) const; // Never returns NULL - const char *operator[] (const char *name) const; // Can return NULL + const char *operator[] (const char *name) const + { + return GetString(name, nullptr); + } bool exists(const char *name); private: LangMap allStrings; - TArray currentLanguageSet; + TArray> currentLanguageSet; void LoadLanguage (int lumpnum); static size_t ProcessEscapes (char *str); diff --git a/src/zstring.cpp b/src/zstring.cpp index 27ecd1356..524eff936 100644 --- a/src/zstring.cpp +++ b/src/zstring.cpp @@ -486,7 +486,7 @@ void FString::DeleteLastCharacter() { if (Len() == 0) return; auto pos = Len() - 1; - while (pos > 0 && Chars[pos] >= 0x80 && Chars[pos] < 0xc0) pos--; + while (pos > 0 && uint8_t(Chars[pos]) >= 0x80 && uint8_t(Chars[pos]) < 0xc0) pos--; if (pos <= 0) { Data()->Release();