diff options
author | corvid <corvid@lavabit.com> | 2011-11-11 04:26:41 +0000 |
---|---|---|
committer | corvid <corvid@lavabit.com> | 2011-11-11 04:26:41 +0000 |
commit | 980fe05f47b9d6dd8626b5ea021e2c16807ff5ca (patch) | |
tree | 2e5670d74d8fcfb8e7f6b84ffaf5f77b74855746 /lout/misc.hh | |
parent | 119aa95ed6bc612dd4ef7a3121d9bf220148aaa4 (diff) |
locale-independent ASCII character case handling
Basically, I and i are different letters in Turkic languages, and this
causes problems for str(n)casecmp and toupper/tolower in these locales
when dillo is dealing with ASCII.
Diffstat (limited to 'lout/misc.hh')
-rw-r--r-- | lout/misc.hh | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/lout/misc.hh b/lout/misc.hh index e78e7576..2a8584eb 100644 --- a/lout/misc.hh +++ b/lout/misc.hh @@ -43,6 +43,27 @@ inline int roundInt(double d) return (int) ((d > 0) ? (d + 0.5) : (d - 0.5)); } +inline int AsciiTolower(char c) +{ + return ((c >= 'A' && c <= 'Z') ? c + 0x20 : c); +} + +inline int AsciiToupper(char c) +{ + return ((c >= 'a' && c <= 'z') ? c - 0x20 : c); +} + +inline int AsciiStrcasecmp(const char *s1, const char *s2) +{ + int ret = 0; + + while ((*s1 || *s2) && !(ret = AsciiTolower(*s1) - AsciiTolower(*s2))) { + s1++; + s2++; + } + return ret; +} + /** * \brief Instances of a sub class of this interface may be compared (less, * greater). |