From 67b8ca70fabfe50513502f866358d2465bd30e6a Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sun, 11 Jan 2009 17:24:15 +0100 Subject: [PATCH] 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. --- src/charset.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/charset.cpp b/src/charset.cpp index c82af514..f8c9c723 100644 --- a/src/charset.cpp +++ b/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; }