diff --git a/Aquaria/UserSettings.cpp b/Aquaria/UserSettings.cpp index e9ab64d..d97dc23 100644 --- a/Aquaria/UserSettings.cpp +++ b/Aquaria/UserSettings.cpp @@ -559,6 +559,8 @@ void UserSettings::load(bool doApply, const std::string &overrideFile) setUsedLocale(system.locale); } + core->initLocalization(); + if (doApply) apply(); } diff --git a/BBGE/Base.cpp b/BBGE/Base.cpp index bd81618..24ab103 100644 --- a/BBGE/Base.cpp +++ b/BBGE/Base.cpp @@ -152,6 +152,60 @@ unsigned hash(const std::string &string) /* hash * 33 + c */ + +static unsigned char lowerToUpperTable[256]; +static unsigned char upperToLowerTable[256]; + +void initCharTranslationTables(const std::map& tab) +{ + for (unsigned int i = 0; i < 256; ++i) + { + lowerToUpperTable[i] = i; + upperToLowerTable[i] = i; + } + for (unsigned char i = 'a'; i <= 'z'; ++i) + { + lowerToUpperTable[i] = i - 'a' + 'A'; + upperToLowerTable[i - 'a' + 'A'] = i; + } + + for (std::map::const_iterator it = tab.begin(); it != tab.end(); ++it) + { + lowerToUpperTable[it->first] = it->second; + upperToLowerTable[it->second] = it->first; + } +} + +struct TransatableStaticInit +{ + TransatableStaticInit() + { + std::map dummy; + initCharTranslationTables(dummy); + } +}; +static TransatableStaticInit _transtable_static_init; + +static unsigned char charIsUpper(unsigned char c) +{ + return c == upperToLowerTable[c]; +} + +static unsigned char charIsLower(unsigned char c) +{ + return c == lowerToUpperTable[c]; +} + +static unsigned char charToLower(unsigned char c) +{ + return upperToLowerTable[c]; +} + +static unsigned char charToUpper(unsigned char c) +{ + return lowerToUpperTable[c]; +} + std::string splitCamelCase(const std::string &input) { std::string result; @@ -160,7 +214,7 @@ std::string splitCamelCase(const std::string &input) { if (last == 1) { - if (input[i] >= 'A' && input[i] <= 'Z') + if (charIsUpper(input[i])) { result += ' '; } @@ -168,7 +222,7 @@ std::string splitCamelCase(const std::string &input) result += input[i]; - if (input[i] >= 'A' && input[i] <= 'Z') + if (charIsUpper(input[i])) { last = 2; } @@ -201,22 +255,6 @@ bool isVectorInRect(const Vector &vec, const Vector &coord1, const Vector &coord return (vec.x > coord1.x && vec.x < coord2.x && vec.y > coord1.y && vec.y < coord2.y); } -static char charToUpper(char c) -{ - if (c >= 'a' && c <= 'z') c = c - 'a' + 'A'; - if ((unsigned char)c >= 0xE0 && (unsigned char)c <= 0xFF) - c = c - 0xE0 + 0xC0; - return c; -} - -static char charToLower(char c) -{ - if (c >= 'A' && c <= 'Z') c = c-'A' + 'a'; - if ((unsigned char)c >= 0xC0 && (unsigned char)c <= 0xDF) - c = c-0xC0+0xE0; - return c; -} - void stringToUpper(std::string &s) { for (int i = 0; i < s.size(); i++) diff --git a/BBGE/Base.h b/BBGE/Base.h index 624414c..afc7c61 100644 --- a/BBGE/Base.h +++ b/BBGE/Base.h @@ -204,6 +204,7 @@ struct IntPair std::string numToZeroString(int num, int zeroes); bool chance(int perc); bool chancef(float p); +void initCharTranslationTables(const std::map& tab); void stringToUpper(std::string &s); void stringToLower(std::string &s); void stringToLowerUserData(std::string &s); diff --git a/BBGE/Core.cpp b/BBGE/Core.cpp index 798dfdf..eb20437 100644 --- a/BBGE/Core.cpp +++ b/BBGE/Core.cpp @@ -1293,6 +1293,8 @@ void Core::init() initInputCodeMap(); + initLocalization(); + //glfwSetWindowSizeCallback(lockWindowSize); } @@ -5164,3 +5166,23 @@ void Core::setupFileAccess() debugLog("Done"); #endif } + +void Core::initLocalization() +{ + InStream in(localisePath("data/localecase.txt")); + if(!in) + { + debugLog("data/localecase.txt does not exist, using internal locale data"); + return; + } + + std::string low, up; + std::map trans; + while(in) + { + in >> low >> up; + trans[low[0]] = up[0]; + } + initCharTranslationTables(trans); +} + diff --git a/BBGE/Core.h b/BBGE/Core.h index 4089ce6..731f8d7 100644 --- a/BBGE/Core.h +++ b/BBGE/Core.h @@ -1310,6 +1310,8 @@ public: virtual void onBackgroundUpdate(); + void initLocalization(); + protected: std::string fpsDebugString; diff --git a/files/data/localecase.txt b/files/data/localecase.txt new file mode 100644 index 0000000..6e16f82 --- /dev/null +++ b/files/data/localecase.txt @@ -0,0 +1,60 @@ +a A +b B +c C +d D +e E +f F +g G +h H +i I +j J +k K +l L +m M +n N +o O +p P +q Q +r R +s S +t T +u U +v V +w W +x X +y Y +z Z + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/files/locales/ru/data/localecase.txt b/files/locales/ru/data/localecase.txt new file mode 100644 index 0000000..15b00d7 --- /dev/null +++ b/files/locales/ru/data/localecase.txt @@ -0,0 +1,72 @@ +a A +b B +c C +d D +e E +f F +g G +h H +i I +j J +k K +l L +m M +n N +o O +p P +q Q +r R +s S +t T +u U +v V +w W +x X +y Y +z Z + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +