From 12c5c1d3e3906e18a96ec380605d2f1504fc3d3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reimar=20D=C3=B6ffinger?= Date: Wed, 6 Mar 2013 14:00:22 +0200 Subject: [PATCH 1/2] avstring: Add locale independent versions of some ctype.h functions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Storsjö --- doc/APIchanges | 3 +++ libavutil/avstring.c | 22 ++++++++++++++++++++++ libavutil/avstring.h | 20 ++++++++++++++++++++ libavutil/version.h | 2 +- 4 files changed, 46 insertions(+), 1 deletion(-) diff --git a/doc/APIchanges b/doc/APIchanges index b58f4da522..d7d95df475 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -13,6 +13,9 @@ libavutil: 2012-10-22 API changes, most recent first: +2013-xx-xx - xxxxxxx - lavu 52.8.0 - avstring.h + Add av_isdigit, av_isgraph, av_isspace, av_isxdigit. + 2013-xx-xx - xxxxxxx - lavfi 3.4.0 - avfiltergraph.h Add resample_lavr_opts to AVFilterGraph for setting libavresample options for auto-inserted resample filters. diff --git a/libavutil/avstring.c b/libavutil/avstring.c index 625f723686..6ce0310c1a 100644 --- a/libavutil/avstring.c +++ b/libavutil/avstring.c @@ -213,6 +213,28 @@ const char *av_dirname(char *path) return path; } +int av_isdigit(int c) +{ + return c >= '0' && c <= '9'; +} + +int av_isgraph(int c) +{ + return c > 32 && c < 127; +} + +int av_isspace(int c) +{ + return c == ' ' || c == '\f' || c == '\n' || c == '\r' || c == '\t' || + c == '\v'; +} + +int av_isxdigit(int c) +{ + c = av_tolower(c); + return av_isdigit(c) || (c >= 'a' && c <= 'z'); +} + #ifdef TEST int main(void) diff --git a/libavutil/avstring.h b/libavutil/avstring.h index e0e6ed26f5..b7d10983c3 100644 --- a/libavutil/avstring.h +++ b/libavutil/avstring.h @@ -151,6 +151,21 @@ char *av_d2str(double d); */ char *av_get_token(const char **buf, const char *term); +/** + * Locale-independent conversion of ASCII isdigit. + */ +int av_isdigit(int c); + +/** + * Locale-independent conversion of ASCII isgraph. + */ +int av_isgraph(int c); + +/** + * Locale-independent conversion of ASCII isspace. + */ +int av_isspace(int c); + /** * Locale-independent conversion of ASCII characters to uppercase. */ @@ -171,6 +186,11 @@ static inline int av_tolower(int c) return c; } +/** + * Locale-independent conversion of ASCII isxdigit. + */ +int av_isxdigit(int c); + /* * Locale-independent case-insensitive compare. * @note This means only ASCII-range characters are case-insensitive diff --git a/libavutil/version.h b/libavutil/version.h index 8d7e378994..38b11a408d 100644 --- a/libavutil/version.h +++ b/libavutil/version.h @@ -37,7 +37,7 @@ */ #define LIBAVUTIL_VERSION_MAJOR 52 -#define LIBAVUTIL_VERSION_MINOR 7 +#define LIBAVUTIL_VERSION_MINOR 8 #define LIBAVUTIL_VERSION_MICRO 0 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ From efa7f4202088c70caba11d7834641bc6eaf41830 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reimar=20D=C3=B6ffinger?= Date: Sun, 3 Mar 2013 11:17:50 +0100 Subject: [PATCH 2/2] Use the avstring.h locale-independent character type functions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Make sure the behavior does not change with the locale. Signed-off-by: Martin Storsjö --- avprobe.c | 5 +++-- avserver.c | 20 ++++++++++---------- cmdutils.c | 2 +- compat/strtod.c | 3 +-- libavcodec/dvdsubdec.c | 3 ++- libavcodec/utils.c | 8 ++++---- libavfilter/af_channelmap.c | 8 ++++---- libavfilter/avfiltergraph.c | 1 - libavfilter/graphparser.c | 1 - libavfilter/vf_libopencv.c | 2 +- libavformat/hls.c | 2 +- libavformat/hlsproto.c | 2 +- libavformat/http.c | 6 +++--- libavformat/httpauth.c | 5 ++--- libavformat/oggparsevorbis.c | 2 +- libavformat/rtmphttp.c | 2 +- libavformat/urldecode.c | 3 +-- libavformat/utils.c | 10 +++++----- libavutil/avstring.c | 3 +-- libavutil/common.h | 1 - libavutil/dict.c | 3 +-- libavutil/eval.c | 3 ++- libavutil/parseutils.c | 4 ++-- 23 files changed, 47 insertions(+), 52 deletions(-) diff --git a/avprobe.c b/avprobe.c index 38b74a3bae..2f15d5ce2a 100644 --- a/avprobe.c +++ b/avprobe.c @@ -23,6 +23,7 @@ #include "libavformat/avformat.h" #include "libavcodec/avcodec.h" +#include "libavutil/avstring.h" #include "libavutil/opt.h" #include "libavutil/pixdesc.h" #include "libavutil/dict.h" @@ -302,7 +303,7 @@ static void old_print_object_header(const char *name) str = p = av_strdup(name); while (*p) { - *p = toupper(*p); + *p = av_toupper(*p); p++; } @@ -319,7 +320,7 @@ static void old_print_object_footer(const char *name) str = p = av_strdup(name); while (*p) { - *p = toupper(*p); + *p = av_toupper(*p); p++; } diff --git a/avserver.c b/avserver.c index ad7bc78f0c..2ab19d0bb8 100644 --- a/avserver.c +++ b/avserver.c @@ -1113,7 +1113,7 @@ static int extract_rates(char *rates, int ratelen, const char *request) if (av_strncasecmp(p, "Pragma:", 7) == 0) { const char *q = p + 7; - while (*q && *q != '\n' && isspace(*q)) + while (*q && *q != '\n' && av_isspace(*q)) q++; if (av_strncasecmp(q, "stream-switch-entry=", 20) == 0) { @@ -1135,7 +1135,7 @@ static int extract_rates(char *rates, int ratelen, const char *request) if (stream_no < ratelen && stream_no >= 0) rates[stream_no] = rate_no; - while (*q && *q != '\n' && !isspace(*q)) + while (*q && *q != '\n' && !av_isspace(*q)) q++; } @@ -1246,7 +1246,7 @@ static void get_word(char *buf, int buf_size, const char **pp) p = *pp; skip_spaces(&p); q = buf; - while (!isspace(*p) && *p != '\0') { + while (!av_isspace(*p) && *p != '\0') { if ((q - buf) < buf_size - 1) *q++ = *p; p++; @@ -1263,7 +1263,7 @@ static void get_arg(char *buf, int buf_size, const char **pp) int quote; p = *pp; - while (isspace(*p)) p++; + while (av_isspace(*p)) p++; q = buf; quote = 0; if (*p == '\"' || *p == '\'') @@ -1273,7 +1273,7 @@ static void get_arg(char *buf, int buf_size, const char **pp) if (*p == quote) break; } else { - if (isspace(*p)) + if (av_isspace(*p)) break; } if (*p == '\0') @@ -1377,7 +1377,7 @@ static IPAddressACL* parse_dynamic_acl(FFStream *stream, HTTPContext *c) break; line_num++; p = line; - while (isspace(*p)) + while (av_isspace(*p)) p++; if (*p == '\0' || *p == '#') continue; @@ -1528,7 +1528,7 @@ static int http_parse_request(HTTPContext *c) for (p = c->buffer; *p && *p != '\r' && *p != '\n'; ) { if (av_strncasecmp(p, "User-Agent:", 11) == 0) { useragent = p + 11; - if (*useragent && *useragent != '\n' && isspace(*useragent)) + if (*useragent && *useragent != '\n' && av_isspace(*useragent)) useragent++; break; } @@ -1654,7 +1654,7 @@ static int http_parse_request(HTTPContext *c) char *eoh; char hostbuf[260]; - while (isspace(*hostinfo)) + while (av_isspace(*hostinfo)) hostinfo++; eoh = strchr(hostinfo, '\n'); @@ -4060,7 +4060,7 @@ static int parse_ffconfig(const char *filename) break; line_num++; p = line; - while (isspace(*p)) + while (av_isspace(*p)) p++; if (*p == '\0' || *p == '#') continue; @@ -4198,7 +4198,7 @@ static int parse_ffconfig(const char *filename) get_arg(arg, sizeof(arg), &p); p1 = arg; fsize = strtod(p1, &p1); - switch(toupper(*p1)) { + switch(av_toupper(*p1)) { case 'K': fsize *= 1024; break; diff --git a/cmdutils.c b/cmdutils.c index fa5632672a..3dbb722d21 100644 --- a/cmdutils.c +++ b/cmdutils.c @@ -1289,7 +1289,7 @@ int show_help(void *optctx, const char *opt, const char *arg) int read_yesno(void) { int c = getchar(); - int yesno = (toupper(c) == 'Y'); + int yesno = (av_toupper(c) == 'Y'); while (c != '\n' && c != EOF) c = getchar(); diff --git a/compat/strtod.c b/compat/strtod.c index 7e979e8be6..258909f409 100644 --- a/compat/strtod.c +++ b/compat/strtod.c @@ -19,7 +19,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include #include #include @@ -49,7 +48,7 @@ double avpriv_strtod(const char *nptr, char **endptr) double res; /* Skip leading spaces */ - while (isspace(*nptr)) + while (av_isspace(*nptr)) nptr++; if (!av_strncasecmp(nptr, "infinity", 8)) { diff --git a/libavcodec/dvdsubdec.c b/libavcodec/dvdsubdec.c index 7afdd27b18..ae16f05e4c 100644 --- a/libavcodec/dvdsubdec.c +++ b/libavcodec/dvdsubdec.c @@ -23,6 +23,7 @@ #include "dsputil.h" #include "libavutil/colorspace.h" #include "libavutil/imgutils.h" +#include "libavutil/avstring.h" //#define DEBUG @@ -522,7 +523,7 @@ static int dvdsub_init(AVCodecContext *avctx) ctx->has_palette = 1; for (i = 0; i < 16; i++) { ctx->palette[i] = strtoul(p, &p, 16); - while (*p == ',' || isspace(*p)) + while (*p == ',' || av_isspace(*p)) p++; } } else if (!strncmp("size:", cur, 5)) { diff --git a/libavcodec/utils.c b/libavcodec/utils.c index b2fdd32458..2a78f7fc0e 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -2105,10 +2105,10 @@ int avpriv_unlock_avformat(void) unsigned int avpriv_toupper4(unsigned int x) { - return toupper(x & 0xFF) - + (toupper((x >> 8) & 0xFF) << 8) - + (toupper((x >> 16) & 0xFF) << 16) - + (toupper((x >> 24) & 0xFF) << 24); + return av_toupper(x & 0xFF) + + (av_toupper((x >> 8) & 0xFF) << 8) + + (av_toupper((x >> 16) & 0xFF) << 16) + + (av_toupper((x >> 24) & 0xFF) << 24); } #if !HAVE_THREADS diff --git a/libavfilter/af_channelmap.c b/libavfilter/af_channelmap.c index 8b72d5bc9f..f741881f41 100644 --- a/libavfilter/af_channelmap.c +++ b/libavfilter/af_channelmap.c @@ -150,17 +150,17 @@ static av_cold int channelmap_init(AVFilterContext *ctx, const char *args) } else { char *dash = strchr(mapping, '-'); if (!dash) { // short mapping - if (isdigit(*mapping)) + if (av_isdigit(*mapping)) mode = MAP_ONE_INT; else mode = MAP_ONE_STR; - } else if (isdigit(*mapping)) { - if (isdigit(*(dash+1))) + } else if (av_isdigit(*mapping)) { + if (av_isdigit(*(dash+1))) mode = MAP_PAIR_INT_INT; else mode = MAP_PAIR_INT_STR; } else { - if (isdigit(*(dash+1))) + if (av_isdigit(*(dash+1))) mode = MAP_PAIR_STR_INT; else mode = MAP_PAIR_STR_STR; diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c index 97af5d0323..09b32f3f42 100644 --- a/libavfilter/avfiltergraph.c +++ b/libavfilter/avfiltergraph.c @@ -20,7 +20,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include #include #include "libavutil/avassert.h" diff --git a/libavfilter/graphparser.c b/libavfilter/graphparser.c index 04339c8138..d48828ea24 100644 --- a/libavfilter/graphparser.c +++ b/libavfilter/graphparser.c @@ -20,7 +20,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include #include #include diff --git a/libavfilter/vf_libopencv.c b/libavfilter/vf_libopencv.c index e558a4a9c1..25b1c5030b 100644 --- a/libavfilter/vf_libopencv.c +++ b/libavfilter/vf_libopencv.c @@ -177,7 +177,7 @@ static int read_shape_from_file(int *cols, int *rows, int **values, const char * p++; break; } else - (*values)[*cols*i + j] = !!isgraph(*(p++)); + (*values)[*cols*i + j] = !!av_isgraph(*(p++)); } } av_file_unmap(buf, size); diff --git a/libavformat/hls.c b/libavformat/hls.c index 4c0e0c0b63..0d691ec47e 100644 --- a/libavformat/hls.c +++ b/libavformat/hls.c @@ -108,7 +108,7 @@ typedef struct HLSContext { static int read_chomp_line(AVIOContext *s, char *buf, int maxlen) { int len = ff_get_line(s, buf, maxlen); - while (len > 0 && isspace(buf[len - 1])) + while (len > 0 && av_isspace(buf[len - 1])) buf[--len] = '\0'; return len; } diff --git a/libavformat/hlsproto.c b/libavformat/hlsproto.c index b750501c4d..fde7191c35 100644 --- a/libavformat/hlsproto.c +++ b/libavformat/hlsproto.c @@ -71,7 +71,7 @@ typedef struct HLSContext { static int read_chomp_line(AVIOContext *s, char *buf, int maxlen) { int len = ff_get_line(s, buf, maxlen); - while (len > 0 && isspace(buf[len - 1])) + while (len > 0 && av_isspace(buf[len - 1])) buf[--len] = '\0'; return len; } diff --git a/libavformat/http.c b/libavformat/http.c index 9645bd1ffb..730a5b1b2f 100644 --- a/libavformat/http.c +++ b/libavformat/http.c @@ -278,9 +278,9 @@ static int process_line(URLContext *h, char *line, int line_count, p = line; if (line_count == 0) { - while (!isspace(*p) && *p != '\0') + while (!av_isspace(*p) && *p != '\0') p++; - while (isspace(*p)) + while (av_isspace(*p)) p++; s->http_code = strtol(p, &end, 10); @@ -305,7 +305,7 @@ static int process_line(URLContext *h, char *line, int line_count, *p = '\0'; tag = line; p++; - while (isspace(*p)) + while (av_isspace(*p)) p++; if (!av_strcasecmp(tag, "Location")) { av_strlcpy(s->location, p, sizeof(s->location)); diff --git a/libavformat/httpauth.c b/libavformat/httpauth.c index 774ee2134f..b96da3ef12 100644 --- a/libavformat/httpauth.c +++ b/libavformat/httpauth.c @@ -27,7 +27,6 @@ #include "libavutil/md5.h" #include "urldecode.h" #include "avformat.h" -#include static void handle_basic_params(HTTPAuthState *state, const char *key, int key_len, char **dest, int *dest_len) @@ -80,8 +79,8 @@ static void choose_qop(char *qop, int size) char *ptr = strstr(qop, "auth"); char *end = ptr + strlen("auth"); - if (ptr && (!*end || isspace(*end) || *end == ',') && - (ptr == qop || isspace(ptr[-1]) || ptr[-1] == ',')) { + if (ptr && (!*end || av_isspace(*end) || *end == ',') && + (ptr == qop || av_isspace(ptr[-1]) || ptr[-1] == ',')) { av_strlcpy(qop, "auth", size); } else { qop[0] = 0; diff --git a/libavformat/oggparsevorbis.c b/libavformat/oggparsevorbis.c index bb41b52ca2..db462fc865 100644 --- a/libavformat/oggparsevorbis.c +++ b/libavformat/oggparsevorbis.c @@ -122,7 +122,7 @@ ff_vorbis_comment(AVFormatContext * as, AVDictionary **m, const uint8_t *buf, in } for (j = 0; j < tl; j++) - tt[j] = toupper(t[j]); + tt[j] = av_toupper(t[j]); tt[tl] = 0; memcpy(ct, v, vl); diff --git a/libavformat/rtmphttp.c b/libavformat/rtmphttp.c index 80a983bd11..e67abba57c 100644 --- a/libavformat/rtmphttp.c +++ b/libavformat/rtmphttp.c @@ -236,7 +236,7 @@ static int rtmp_http_open(URLContext *h, const char *uri, int flags) goto fail; } } - while (off > 0 && isspace(rt->client_id[off - 1])) + while (off > 0 && av_isspace(rt->client_id[off - 1])) off--; rt->client_id[off] = '\0'; diff --git a/libavformat/urldecode.c b/libavformat/urldecode.c index 32460da4f9..49af9ba1e0 100644 --- a/libavformat/urldecode.c +++ b/libavformat/urldecode.c @@ -26,7 +26,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include #include #include "libavutil/mem.h" @@ -54,7 +53,7 @@ char *ff_urldecode(const char *url) if (c == '%' && s + 2 < url_len) { char c2 = url[s++]; char c3 = url[s++]; - if (isxdigit(c2) && isxdigit(c3)) { + if (av_isxdigit(c2) && av_isxdigit(c3)) { c2 = av_tolower(c2); c3 = av_tolower(c3); diff --git a/libavformat/utils.c b/libavformat/utils.c index be5a5caabf..a89e956d8d 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -3050,11 +3050,11 @@ int av_get_frame_filename(char *buf, int buf_size, if (c == '%') { do { nd = 0; - while (isdigit(*p)) { + while (av_isdigit(*p)) { nd = nd * 10 + *p++ - '0'; } c = *p++; - } while (isdigit(c)); + } while (av_isdigit(c)); switch(c) { case '%': @@ -3255,7 +3255,7 @@ int ff_hex_to_data(uint8_t *data, const char *p) p += strspn(p, SPACE_CHARS); if (*p == '\0') break; - c = toupper((unsigned char) *p++); + c = av_toupper((unsigned char) *p++); if (c >= '0' && c <= '9') c = c - '0'; else if (c >= 'A' && c <= 'F') @@ -3365,7 +3365,7 @@ void ff_parse_key_value(const char *str, ff_parse_key_val_cb callback_get_buf, int key_len, dest_len = 0; /* Skip whitespace and potential commas. */ - while (*ptr && (isspace(*ptr) || *ptr == ',')) + while (*ptr && (av_isspace(*ptr) || *ptr == ',')) ptr++; if (!*ptr) break; @@ -3398,7 +3398,7 @@ void ff_parse_key_value(const char *str, ff_parse_key_val_cb callback_get_buf, if (*ptr == '\"') ptr++; } else { - for (; *ptr && !(isspace(*ptr) || *ptr == ','); ptr++) + for (; *ptr && !(av_isspace(*ptr) || *ptr == ','); ptr++) if (dest && dest < dest_end) *dest++ = *ptr; } diff --git a/libavutil/avstring.c b/libavutil/avstring.c index 6ce0310c1a..973ba4357e 100644 --- a/libavutil/avstring.c +++ b/libavutil/avstring.c @@ -23,7 +23,6 @@ #include #include #include -#include #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/common.h b/libavutil/common.h index cc4df16e4a..caa6b1963b 100644 --- a/libavutil/common.h +++ b/libavutil/common.h @@ -26,7 +26,6 @@ #ifndef AVUTIL_COMMON_H #define AVUTIL_COMMON_H -#include #include #include #include diff --git a/libavutil/dict.c b/libavutil/dict.c index 6532a56561..9ac4831688 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 #include #include "avstring.h" @@ -50,7 +49,7 @@ av_dict_get(AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int for(; icount; 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 a0e968dc34..0ca7472ffd 100644 --- a/libavutil/eval.c +++ b/libavutil/eval.c @@ -31,6 +31,7 @@ #include "eval.h" #include "log.h" #include "mathematics.h" +#include "avstring.h" typedef struct Parser { const AVClass *class; @@ -503,7 +504,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 917451eee7..0e3fd9eab5 100644 --- a/libavutil/parseutils.c +++ b/libavutil/parseutils.c @@ -385,7 +385,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++; @@ -591,7 +591,7 @@ int av_parse_time(int64_t *timeval, const char *timestr, int duration) int val, n; q++; for (val = 0, n = 100000; n >= 1; n /= 10, q++) { - if (!isdigit(*q)) + if (!av_isdigit(*q)) break; val += n * (*q - '0'); }