mirror of
https://github.com/glest/glest-source.git
synced 2025-08-15 04:43:58 +02:00
- clipboard working now for utf8
This commit is contained in:
@@ -64,6 +64,8 @@ namespace Shared { namespace Util {
|
||||
void strrev_utf8(std::string &p);
|
||||
bool is_string_all_ascii(std::string str);
|
||||
|
||||
int getUTF8_Width(const char *str);
|
||||
|
||||
}}
|
||||
|
||||
#endif // _SHARED_UTIL_W_STRING_H__
|
||||
|
@@ -309,6 +309,31 @@ namespace Shared { namespace Util {
|
||||
return result;
|
||||
}
|
||||
|
||||
int getUTF8_Width(const char *str) {
|
||||
int ewidth = 0;
|
||||
const unsigned char *s = (const unsigned char *)str;
|
||||
if (!str) {
|
||||
return 0;
|
||||
}
|
||||
if(*s <= 0x7F) {
|
||||
ewidth = 0;
|
||||
}
|
||||
else if (0xC2 <= *s && *s <= 0xDF) {
|
||||
ewidth = 1;
|
||||
}
|
||||
else if (0xE0 <= *s && *s <= 0xEF) {
|
||||
ewidth = 2;
|
||||
}
|
||||
else if (0xF0 <= *s && *s <= 0xF4) {
|
||||
ewidth = 3;
|
||||
}
|
||||
else {
|
||||
ewidth = 0;
|
||||
}
|
||||
|
||||
for ( ; *s && ewidth > 0; s++, ewidth--);
|
||||
|
||||
return s - (const unsigned char *)str + 1;
|
||||
}
|
||||
|
||||
}}
|
||||
|
Reference in New Issue
Block a user