]> granicus.if.org Git - taglib/commitdiff
tolower() depends on the current locale.
authorTsuda Kageyu <tsuda.kageyu@gmail.com>
Tue, 8 Nov 2016 12:39:53 +0000 (21:39 +0900)
committerTsuda Kageyu <tsuda.kageyu@gmail.com>
Tue, 8 Nov 2016 12:39:53 +0000 (21:39 +0900)
It's much easier to write our own function than to use locales properly.

taglib/toolkit/tutils.h

index e3e4f6c36e94b68fbf9f670cc3cf102d0e44d410..365cfcab205308eface4fdf59f81acb6fd533c8b 100644 (file)
@@ -222,15 +222,27 @@ namespace TagLib
       }
 
       /*!
-       * Returns whether the two strings s1 and s2 are equal, ignoring the case of
-       * the characters.
+       * Converts the letter c to lower case, not depending on the locale.
+       */
+      inline int toLowerCase(char c)
+      {
+        if('A' <= c && c <= 'Z')
+          return c + ('a' - 'A');
+        else
+          return c;
+      }
+
+      /*!
+       * Returns whether the two strings s1 and s2 are equal, ignoring the case
+       * of the characters.  This only supports US-ASCII and does not depend on
+       * the current locale.
        *
        * We took the trouble to define this one here, since there are some
        * incompatible variations of case insensitive strcmp().
        */
       inline bool equalsIgnoreCase(const char *s1, const char *s2)
       {
-        while(*s1 != '\0' && *s2 != '\0' && ::tolower(*s1) == ::tolower(*s2)) {
+        while(*s1 != '\0' && *s2 != '\0' && toLowerCase(*s1) == toLowerCase(*s2)) {
           s1++;
           s2++;
         }