From 96949dafcca87f65902bd77a0bc56007d9cead70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reimar=20D=C3=B6ffinger?= Date: Wed, 2 Nov 2011 20:17:25 +0100 Subject: Replace all strcasecmp/strncasecmp usages. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- libavutil/avstring.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'libavutil/avstring.c') 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 -- cgit v1.2.3