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.
master
Max Kellermann 17 years ago
parent 73c166a029
commit 67b8ca70fa
  1. 9
      src/charset.cpp

@ -34,11 +34,16 @@
namespace
{
char *locale_charset = 0;
static inline bool char_non_ascii(char ch)
{
return (ch & 0x80) != 0;
}
bool has_non_ascii_chars(const char *s)
{
for (; s; s++)
if (*s < 0)
if (char_non_ascii(*s))
return true;
return false;
}
@ -46,7 +51,7 @@ namespace
bool has_non_ascii_chars(const std::string &s)
{
for (std::string::const_iterator it = s.begin(); it != s.end(); it++)
if (*it < 0)
if (char_non_ascii(*it))
return true;
return false;
}

Loading…
Cancel
Save