mirror of
https://github.com/AquariaOSE/Aquaria.git
synced 2025-10-08 23:41:06 +00:00
Add custom upper<->lowercase translation tables for better localization support.
Translation tables by Henrik Holst.
This commit is contained in:
parent
7a9df46830
commit
7de589e275
7 changed files with 215 additions and 18 deletions
|
@ -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<unsigned char, unsigned char>& 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<unsigned char, unsigned char>::const_iterator it = tab.begin(); it != tab.end(); ++it)
|
||||
{
|
||||
lowerToUpperTable[it->first] = it->second;
|
||||
upperToLowerTable[it->second] = it->first;
|
||||
}
|
||||
}
|
||||
|
||||
struct TransatableStaticInit
|
||||
{
|
||||
TransatableStaticInit()
|
||||
{
|
||||
std::map<unsigned char, unsigned char> 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++)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue