diff --git a/inc/config.h b/inc/config.h index 10593c8..0ee08e3 100644 --- a/inc/config.h +++ b/inc/config.h @@ -35,22 +35,6 @@ public: ChatterItem (StringRef name, float repeat, float duration) : name (name), repeat (repeat), duration (duration) { } }; -// language hasher -struct HashLangString { - uint32 operator () (const String &key) const { - auto str = reinterpret_cast (const_cast (key.chars ())); - uint32 hash = 0; - - while (*str++) { - if (!isalnum (*str)) { - continue; - } - hash = ((*str << 5) + hash) + *str; - } - return hash; - } -}; - // mostly config stuff, and some stuff dealing with menus class BotConfig final : public Singleton { public: @@ -73,7 +57,7 @@ private: StringArray m_logos; StringArray m_avatars; - HashMap m_language; + HashMap > m_language; HashMap m_difficulty; // default tables for personality weapon preferences, overridden by weapon.cfg @@ -148,9 +132,12 @@ private: if (line.empty ()) { return true; } - return line.substr (0, 1).findFirstOf ("#/; \n\r") != String::InvalidIndex; + return line.substr (0, 1).findFirstOf ("#/;") != String::InvalidIndex; }; + // hash the lang string, only the letters + uint32 hashLangString (const char *input); + public: // checks whether chat banks contains messages diff --git a/src/config.cpp b/src/config.cpp index 15cd042..c84074d 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -495,7 +495,7 @@ void BotConfig::loadLanguageConfig () { } if (!lang.second.empty () && !lang.first.empty ()) { - m_language[lang.first.trim ()] = lang.second.trim (); + m_language[hashLangString (lang.first.trim ().chars ())] = lang.second; } } else if (line.startsWith ("[TRANSLATED]") && !temp.empty ()) { @@ -756,9 +756,23 @@ const char *BotConfig::translate (StringRef input) { if (game.isDedicated ()) { return input.chars (); } + auto hash = hashLangString (input.chars ()); - if (m_language.has (input)) { - return m_language[input.chars ()].chars (); + if (m_language.has (hash)) { + return m_language[hash].chars (); } return input.chars (); // nothing found -} \ No newline at end of file +} + +uint32 BotConfig::hashLangString (const char *input) { + auto str = reinterpret_cast (const_cast (input)); + uint32 hash = 0; + + while (*str++) { + if (!isalnum (*str)) { + continue; + } + hash = ((*str << 5) + hash) + *str; + } + return hash; +}