diff options
author | Reimar Döffinger <Reimar.Doeffinger@gmx.de> | 2013-03-03 11:17:50 +0100 |
---|---|---|
committer | Reimar Döffinger <Reimar.Doeffinger@gmx.de> | 2013-03-03 21:44:10 +0100 |
commit | 88d55b827d5ecac94c9ec399d219cc02b46ed694 (patch) | |
tree | 6aa644bd0328757eae325c5ba61df169d75cfa6e /libavutil | |
parent | 2cffe38df3df8ee1ec0fea0b2a2d3fed6e75da0d (diff) |
Remove incorrect use of ctype.h functions.
As far as I can tell the code should not change behaviour
depending on locale in any of these places.
Signed-off-by: Reimar Döffinger <Reimar.Doeffinger@gmx.de>
Diffstat (limited to 'libavutil')
-rw-r--r-- | libavutil/avstring.c | 3 | ||||
-rw-r--r-- | libavutil/avstring.h | 33 | ||||
-rw-r--r-- | libavutil/common.h | 1 | ||||
-rw-r--r-- | libavutil/dict.c | 3 | ||||
-rw-r--r-- | libavutil/eval.c | 3 | ||||
-rw-r--r-- | libavutil/parseutils.c | 10 |
6 files changed, 42 insertions, 11 deletions
diff --git a/libavutil/avstring.c b/libavutil/avstring.c index e2422c0a59..9ad1e12711 100644 --- a/libavutil/avstring.c +++ b/libavutil/avstring.c @@ -23,7 +23,6 @@ #include <stdint.h> #include <stdio.h> #include <string.h> -#include <ctype.h> #include "config.h" #include "common.h" @@ -43,7 +42,7 @@ int av_strstart(const char *str, const char *pfx, const char **ptr) int av_stristart(const char *str, const char *pfx, const char **ptr) { - while (*pfx && toupper((unsigned)*pfx) == toupper((unsigned)*str)) { + while (*pfx && av_toupper((unsigned)*pfx) == av_toupper((unsigned)*str)) { pfx++; str++; } diff --git a/libavutil/avstring.h b/libavutil/avstring.h index b08d78ee8c..3896b5f2bb 100644 --- a/libavutil/avstring.h +++ b/libavutil/avstring.h @@ -186,6 +186,30 @@ char *av_get_token(const char **buf, const char *term); char *av_strtok(char *s, const char *delim, char **saveptr); /** + * Locale-independent conversion of ASCII isdigit. + */ +static inline int av_isdigit(int c) +{ + return c >= '0' && c <= '9'; +} + +/** + * Locale-independent conversion of ASCII isgraph. + */ +static inline int av_isgraph(int c) +{ + return c > 32 && c < 127; +} + +/** + * Locale-independent conversion of ASCII isspace. + */ +static inline int av_isspace(int c) +{ + return c == ' ' || c == '\f' || c == '\n' || c == '\r' || c == '\t' || c == '\v'; +} + +/** * Locale-independent conversion of ASCII characters to uppercase. */ static inline int av_toupper(int c) @@ -206,6 +230,15 @@ static inline int av_tolower(int c) } /** + * Locale-independent conversion of ASCII isxdigit. + */ +static inline int av_isxdigit(int c) +{ + c = av_tolower(c); + return av_isdigit(c) || (c >= 'a' && c <= 'z'); +} + +/** * Locale-independent case-insensitive compare. * @note This means only ASCII-range characters are case-insensitive */ diff --git a/libavutil/common.h b/libavutil/common.h index 778c757b69..beaf9f7635 100644 --- a/libavutil/common.h +++ b/libavutil/common.h @@ -26,7 +26,6 @@ #ifndef AVUTIL_COMMON_H #define AVUTIL_COMMON_H -#include <ctype.h> #include <errno.h> #include <inttypes.h> #include <limits.h> diff --git a/libavutil/dict.c b/libavutil/dict.c index 967c9e2fff..3cd7156a04 100644 --- a/libavutil/dict.c +++ b/libavutil/dict.c @@ -18,7 +18,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include <ctype.h> #include <string.h> #include "avstring.h" @@ -50,7 +49,7 @@ av_dict_get(AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int for(; i<m->count; i++){ const char *s= m->elems[i].key; if(flags & AV_DICT_MATCH_CASE) for(j=0; s[j] == key[j] && key[j]; j++); - else for(j=0; toupper(s[j]) == toupper(key[j]) && key[j]; j++); + else for(j=0; av_toupper(s[j]) == av_toupper(key[j]) && key[j]; j++); if(key[j]) continue; if(s[j] && !(flags & AV_DICT_IGNORE_SUFFIX)) diff --git a/libavutil/eval.c b/libavutil/eval.c index 5d202249f0..1449e49468 100644 --- a/libavutil/eval.c +++ b/libavutil/eval.c @@ -33,6 +33,7 @@ #include "log.h" #include "mathematics.h" #include "time.h" +#include "avstring.h" typedef struct Parser { const AVClass *class; @@ -637,7 +638,7 @@ int av_expr_parse(AVExpr **expr, const char *s, return AVERROR(ENOMEM); while (*s) - if (!isspace(*s++)) *wp++ = s[-1]; + if (!av_isspace(*s++)) *wp++ = s[-1]; *wp++ = 0; p.class = &class; diff --git a/libavutil/parseutils.c b/libavutil/parseutils.c index c67f971792..494801e2de 100644 --- a/libavutil/parseutils.c +++ b/libavutil/parseutils.c @@ -426,7 +426,7 @@ static int date_get_num(const char **pp, val = 0; for(i = 0; i < len_max; i++) { c = *p; - if (!isdigit(c)) + if (!av_isdigit(c)) break; val = (val * 10) + c - '0'; p++; @@ -446,8 +446,8 @@ char *av_small_strptime(const char *p, const char *fmt, struct tm *dt) for(;;) { /* consume time string until a non whitespace char is found */ - while (isspace(*fmt)) { - while (isspace(*p)) + while (av_isspace(*fmt)) { + while (av_isspace(*p)) p++; fmt++; } @@ -611,11 +611,11 @@ int av_parse_time(int64_t *timeval, const char *timestr, int duration) int n; q++; for (n = 100000; n >= 1; n /= 10, q++) { - if (!isdigit(*q)) + if (!av_isdigit(*q)) break; microseconds += n * (*q - '0'); } - while (isdigit(*q)) + while (av_isdigit(*q)) q++; } |