From ac6ef8682d1fe8afa9f0a3fcc9eadbad1c903937 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5ns=20Rullg=C3=A5rd?= Date: Sat, 6 Mar 2010 19:41:22 +0000 Subject: [PATCH] Add av_stristr() function This is a case-insensitive version of strstr(). Originally committed as revision 22251 to svn://svn.ffmpeg.org/ffmpeg/trunk --- libavutil/avstring.c | 13 +++++++++++++ libavutil/avstring.h | 13 +++++++++++++ 2 files changed, 26 insertions(+) diff --git a/libavutil/avstring.c b/libavutil/avstring.c index 6d45a9581a..4844e28db2 100644 --- a/libavutil/avstring.c +++ b/libavutil/avstring.c @@ -48,6 +48,19 @@ int av_stristart(const char *str, const char *pfx, const char **ptr) return !*pfx; } +char *av_stristr(const char *s1, const char *s2) +{ + if (!*s2) + return s1; + + do { + if (av_stristart(s1, s2, NULL)) + return s1; + } while (*s1++); + + return NULL; +} + size_t av_strlcpy(char *dst, const char *src, size_t size) { size_t len = 0; diff --git a/libavutil/avstring.h b/libavutil/avstring.h index 4e3f5df169..d9f6a0fa01 100644 --- a/libavutil/avstring.h +++ b/libavutil/avstring.h @@ -46,6 +46,19 @@ int av_strstart(const char *str, const char *pfx, const char **ptr); */ int av_stristart(const char *str, const char *pfx, const char **ptr); +/** + * Locate the first case-independent occurrence in the string s1 of + * the string s2. A zero-length string s2 is considered to match at + * the start of s1. + * + * This function is a case-insensitive version of the standard strstr(). + * + * @param s1 string to search in + * @param s2 string to search for + * @return pointer to the located match within s1 or a null pointer if no match + */ +char *av_stristr(const char *s1, const char *s2); + /** * Copy the string src to dst, but no more than size - 1 bytes, and * null-terminate dst.