Browse code

avstring: Add locale independent implementations of strcasecmp/strncasecmp

Signed-off-by: Martin Storsjö <martin@martin.st>

Reimar Döffinger authored on 2011/11/06 00:20:41
Showing 4 changed files
... ...
@@ -13,6 +13,9 @@ libavutil:   2011-04-18
13 13
 
14 14
 API changes, most recent first:
15 15
 
16
+2011-11-xx - xxxxxxx - lavu 51.14.0
17
+  Add av_strcasecmp() and av_strncasecmp() to avstring.h.
18
+
16 19
 2011-11-xx - xxxxxxx - lavu 51.13.0
17 20
   Add av_toupper()/av_tolower()
18 21
 
... ...
@@ -134,6 +134,27 @@ char *av_get_token(const char **buf, const char *term)
134 134
     return ret;
135 135
 }
136 136
 
137
+int av_strcasecmp(const char *a, const char *b)
138
+{
139
+    uint8_t c1, c2;
140
+    do {
141
+        c1 = av_tolower(*a++);
142
+        c2 = av_tolower(*b++);
143
+    } while (c1 && c1 == c2);
144
+    return c1 - c2;
145
+}
146
+
147
+int av_strncasecmp(const char *a, const char *b, size_t n)
148
+{
149
+    const char *end = a + n;
150
+    uint8_t c1, c2;
151
+    do {
152
+        c1 = av_tolower(*a++);
153
+        c2 = av_tolower(*b++);
154
+    } while (a < end && c1 && c1 == c2);
155
+    return c1 - c2;
156
+}
157
+
137 158
 #ifdef TEST
138 159
 
139 160
 #undef printf
... ...
@@ -151,4 +151,16 @@ static inline int av_tolower(int c)
151 151
     return c;
152 152
 }
153 153
 
154
+/*
155
+ * Locale independent case-insensitive compare.
156
+ * Note: This means only ASCII-range characters are case-insensitive
157
+ */
158
+int av_strcasecmp(const char *a, const char *b);
159
+
160
+/**
161
+ * Locale independent case-insensitive compare.
162
+ * Note: This means only ASCII-range characters are case-insensitive
163
+ */
164
+int av_strncasecmp(const char *a, const char *b, size_t n);
165
+
154 166
 #endif /* AVUTIL_AVSTRING_H */
... ...
@@ -40,7 +40,7 @@
40 40
 #define AV_VERSION(a, b, c) AV_VERSION_DOT(a, b, c)
41 41
 
42 42
 #define LIBAVUTIL_VERSION_MAJOR 51
43
-#define LIBAVUTIL_VERSION_MINOR 13
43
+#define LIBAVUTIL_VERSION_MINOR 14
44 44
 #define LIBAVUTIL_VERSION_MICRO  0
45 45
 
46 46
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \