charset: fix portability for unsigned chars
On some platforms, char is unsigned, and the "non_ascii" check "ch < 0" does not work. Fix that by checking if the highest bit is set.
This commit is contained in:
@@ -35,10 +35,15 @@ namespace
|
|||||||
{
|
{
|
||||||
char *locale_charset = 0;
|
char *locale_charset = 0;
|
||||||
|
|
||||||
|
static inline bool char_non_ascii(char ch)
|
||||||
|
{
|
||||||
|
return (ch & 0x80) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
bool has_non_ascii_chars(const char *s)
|
bool has_non_ascii_chars(const char *s)
|
||||||
{
|
{
|
||||||
for (; s; s++)
|
for (; s; s++)
|
||||||
if (*s < 0)
|
if (char_non_ascii(*s))
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -46,7 +51,7 @@ namespace
|
|||||||
bool has_non_ascii_chars(const std::string &s)
|
bool has_non_ascii_chars(const std::string &s)
|
||||||
{
|
{
|
||||||
for (std::string::const_iterator it = s.begin(); it != s.end(); it++)
|
for (std::string::const_iterator it = s.begin(); it != s.end(); it++)
|
||||||
if (*it < 0)
|
if (char_non_ascii(*it))
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user