Use custom upchar and lochar by default due to accents in font files.

This commit is contained in:
Henrique Santiago
2012-08-07 21:12:36 -03:00
parent 26c682c0dc
commit 466d8e8820
4 changed files with 13 additions and 10 deletions

View File

@@ -101,12 +101,12 @@ std::string utf8_to_latin1(uchar *utf8)
void tolower(std::string& str)
{
boost::to_lower(str);
std::transform(str.begin(), str.end(), str.begin(), lochar);
}
void toupper(std::string& str)
{
boost::to_upper(str);
std::transform(str.begin(), str.end(), str.begin(), upchar);
}
void trim(std::string& str)
@@ -116,14 +116,16 @@ void trim(std::string& str)
char upchar(char c)
{
#if defined(__GNUC__) && __GNUC__ >= 3
return ::toupper(c); // use the one from global scope "ctype.h"
#else
if((c >= 97 && c <= 122) || (c <= -1 && c >= -32))
if((c >= 97 && c <= 122) || (uchar)c >= 224)
c -= 32;
return c;
#endif
}
char lochar(char c)
{
if((c >= 65 && c <= 90) || ((uchar)c >= 192 && (uchar)c <= 223))
c += 32;
return c;
}
void ucwords(std::string& str)

View File

@@ -48,6 +48,7 @@ void toupper(std::string& str);
void trim(std::string& str);
void ucwords(std::string& str);
char upchar(char c);
char lochar(char c);
bool ends_with(const std::string& str, const std::string& test);
bool starts_with(const std::string& str, const std::string& test);
void replace_all(std::string& str, const std::string& search, const std::string& replacement);

View File

@@ -108,7 +108,7 @@ void UIWidget::onFontChange(const std::string& font)
void UIWidget::setText(std::string text)
{
if(m_textOnlyUpperCase)
std::transform(text.begin(), text.end(), text.begin(), toupper);
stdext::toupper(text);
if(m_text == text)
return;