diff options
author | Steven Liu <lq@chinaffmpeg.org> | 2017-04-11 08:05:54 +0800 |
---|---|---|
committer | Steven Liu <lq@chinaffmpeg.org> | 2017-04-11 08:05:54 +0800 |
commit | 0b4d87fad122831206cf600a801d118d1b517a54 (patch) | |
tree | db97abca5341b503c8a0ba0ddeb2e792ea86b2ee | |
parent | 7034009f625dd042234fe90c2a2a8b8fcf8dcb6c (diff) | |
download | ffmpeg-0b4d87fad122831206cf600a801d118d1b517a54.tar.gz |
Revert "avutil/avstring: add av_strreplace API into avstring"
This reverts commit 99e5d81ef997cb88b1a40e6f253f37f7cbf251d9.
-rw-r--r-- | libavutil/avstring.c | 77 | ||||
-rw-r--r-- | libavutil/avstring.h | 5 |
2 files changed, 0 insertions, 82 deletions
diff --git a/libavutil/avstring.c b/libavutil/avstring.c index 52e6e6cd13..1787a1ef54 100644 --- a/libavutil/avstring.c +++ b/libavutil/avstring.c @@ -231,83 +231,6 @@ int av_strncasecmp(const char *a, const char *b, size_t n) return c1 - c2; } -char *av_strreplace(const char *str, const char *from, const char *to) -{ - /* Adjust each of the below values to suit your needs. */ - /* Increment positions cache size initially by this number. */ - size_t cache_sz_inc = 16; - /* Thereafter, each time capacity needs to be increased, - * multiply the increment by this factor. */ - const size_t cache_sz_inc_factor = 3; - /* But never increment capacity by more than this number. */ - const size_t cache_sz_inc_max = 1048576; - - char *pret, *ret = NULL; - const char *pstr2, *pstr = str; - size_t i, count = 0; - uintptr_t *pos_cache_tmp, *pos_cache = NULL; - size_t cache_sz = 0; - size_t cpylen, orglen, retlen, tolen, fromlen = strlen(from); - - /* Find all matches and cache their positions. */ - while ((pstr2 = av_stristr(pstr, from))) { - count++; - /* Increase the cache size when necessary. */ - if (cache_sz < count) { - cache_sz += cache_sz_inc; - pos_cache_tmp = av_realloc(pos_cache, sizeof(*pos_cache) * cache_sz); - if (!pos_cache_tmp) { - goto end_strreplace; - } else pos_cache = pos_cache_tmp; - cache_sz_inc *= cache_sz_inc_factor; - if (cache_sz_inc > cache_sz_inc_max) { - cache_sz_inc = cache_sz_inc_max; - } - } - - pos_cache[count-1] = pstr2 - str; - pstr = pstr2 + fromlen; - } - orglen = pstr - str + strlen(pstr); - /* Allocate memory for the post-replacement string. */ - if (count > 0) { - tolen = strlen(to); - retlen = orglen + (tolen - fromlen) * count; - } else { - retlen = orglen; - } - ret = av_malloc(retlen + 1); - if (!ret) { - goto end_strreplace; - } - - if (!count) { - /* If no matches, then just duplicate the string. */ - av_strlcpy(ret, str, retlen + 1); - } else { - /* Otherwise, duplicate the string whilst performing - * the replacements using the position cache. */ - pret = ret; - memcpy(pret, str, pos_cache[0]); - pret += pos_cache[0]; - for (i = 0; i < count; i++) { - memcpy(pret, to, tolen); - pret += tolen; - pstr = str + pos_cache[i] + fromlen; - cpylen = (i == count-1 ? orglen : pos_cache[i+1]) - pos_cache[i] - fromlen; - memcpy(pret, pstr, cpylen); - pret += cpylen; - } - ret[retlen] = '\0'; - } - -end_strreplace: - /* Free the cache and return the post-replacement string, - * which will be NULL in the event of an error. */ - av_free(pos_cache); - return ret; -} - const char *av_basename(const char *path) { char *p = strrchr(path, '/'); diff --git a/libavutil/avstring.h b/libavutil/avstring.h index 33be8bf484..dd2876990f 100644 --- a/libavutil/avstring.h +++ b/libavutil/avstring.h @@ -266,11 +266,6 @@ int av_strcasecmp(const char *a, const char *b); */ int av_strncasecmp(const char *a, const char *b, size_t n); -/** - * Locale-independent strings replace. - * @note This means only ASCII-range characters are replace - */ -char *av_strreplace(const char *str, const char *from, const char *to); /** * Thread safe basename. |