aboutsummaryrefslogtreecommitdiffstats
path: root/libavutil/avstring.c
diff options
context:
space:
mode:
authorReimar Döffinger <Reimar.Doeffinger@gmx.de>2011-11-02 20:17:25 +0100
committerReimar Döffinger <Reimar.Doeffinger@gmx.de>2011-11-03 19:25:26 +0100
commit96949dafcca87f65902bd77a0bc56007d9cead70 (patch)
treee394623e56efc86b70d3e7fbdefc2555457b3aa3 /libavutil/avstring.c
parent475fb67d0b391ad1e8e3e8e3d65d7e6892e17e7a (diff)
downloadffmpeg-96949dafcca87f65902bd77a0bc56007d9cead70.tar.gz
Replace all strcasecmp/strncasecmp usages.
All current usages of it are incompatible with localization. For example strcasecmp("i", "I") != 0 is possible, but would break many of the places where it is used. Instead use our own implementations that always treat the data as ASCII. Signed-off-by: Reimar Döffinger <Reimar.Doeffinger@gmx.de>
Diffstat (limited to 'libavutil/avstring.c')
-rw-r--r--libavutil/avstring.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/libavutil/avstring.c b/libavutil/avstring.c
index 247cd71745..d167d5245e 100644
--- a/libavutil/avstring.c
+++ b/libavutil/avstring.c
@@ -189,6 +189,33 @@ char *av_strtok(char *s, const char *delim, char **saveptr)
return tok;
}
+#define TOUPPER(c) do { if (c >= 'a' && c <= 'z') c -= 'a' - 'A'; } while (0)
+
+int av_strcasecmp(const char *a, const char *b)
+{
+ uint8_t c1, c2;
+ do {
+ c1 = *a++;
+ c2 = *b++;
+ TOUPPER(c1);
+ TOUPPER(c2);
+ } while (c1 && c1 == c2);
+ return c1 - c2;
+}
+
+int av_strncasecmp(const char *a, const char *b, size_t n)
+{
+ const char *end = a + n;
+ uint8_t c1, c2;
+ do {
+ c1 = *a++;
+ c2 = *b++;
+ TOUPPER(c1);
+ TOUPPER(c2);
+ } while (a < end && c1 && c1 == c2);
+ return c1 - c2;
+}
+
#ifdef TEST
#undef printf