aboutsummaryrefslogtreecommitdiffstats
path: root/libavutil
diff options
context:
space:
mode:
authorStefano Sabatini <stefasab@gmail.com>2011-10-15 00:14:37 +0200
committerStefano Sabatini <stefasab@gmail.com>2011-10-18 18:21:03 +0200
commitb35e9e19e93b0c69303444e9974ee640a924f798 (patch)
tree09c93cf03ae3e1902b312eef74aab72f75180da9 /libavutil
parent88bdf7471f6b8df5106f84b4b4d4cffe4606bcb0 (diff)
downloadffmpeg-b35e9e19e93b0c69303444e9974ee640a924f798.tar.gz
lavu: add av_strtok()
The function strtok_r() is part of the POSIX.1 specification, but is not available on some platforms. We provide an internal implementation, so we do not need to rely on a platform implementation.
Diffstat (limited to 'libavutil')
-rw-r--r--libavutil/avstring.c29
-rw-r--r--libavutil/avstring.h24
2 files changed, 53 insertions, 0 deletions
diff --git a/libavutil/avstring.c b/libavutil/avstring.c
index 4c504482da..247cd71745 100644
--- a/libavutil/avstring.c
+++ b/libavutil/avstring.c
@@ -160,6 +160,35 @@ char *av_get_token(const char **buf, const char *term)
return ret;
}
+char *av_strtok(char *s, const char *delim, char **saveptr)
+{
+ char *tok;
+
+ if (!s && !(s = *saveptr))
+ return NULL;
+
+ /* skip leading delimiters */
+ s += strspn(s, delim);
+
+ /* s now points to the first non delimiter char, or to the end of the string */
+ if (!*s) {
+ *saveptr = NULL;
+ return NULL;
+ }
+ tok = s++;
+
+ /* skip non delimiters */
+ s += strcspn(s, delim);
+ if (*s) {
+ *s = 0;
+ *saveptr = s+1;
+ } else {
+ *saveptr = NULL;
+ }
+
+ return tok;
+}
+
#ifdef TEST
#undef printf
diff --git a/libavutil/avstring.h b/libavutil/avstring.h
index 2be84a9ed0..0b2205a9be 100644
--- a/libavutil/avstring.h
+++ b/libavutil/avstring.h
@@ -141,4 +141,28 @@ char *av_d2str(double d);
*/
char *av_get_token(const char **buf, const char *term);
+/**
+ * Split the string into several tokens which can be accessed by
+ * successive calls to av_strtok().
+ *
+ * A token is defined as a sequence of characters not belonging to the
+ * set specified in delim.
+ *
+ * On the first call to av_strtok(), s should point to the string to
+ * parse, and the value of saveptr is ignored. In subsequent calls, s
+ * should be NULL, and saveptr should be unchanged since the previous
+ * call.
+ *
+ * This function is similar to strtok_r() defined in POSIX.1.
+ *
+ * @param s the string to parse, may be NULL
+ * @param delim 0-terminated list of token delimiters, must be non-NULL
+ * @param saveptr user-provided pointer which points to stored
+ * information necessary for av_strtok() to continue scanning the same
+ * string. saveptr is updated to point to the next character after the
+ * first delimiter found, or to NULL if the string was terminated
+ * @return the found token, or NULL when no token is found
+ */
+char *av_strtok(char *s, const char *delim, char **saveptr);
+
#endif /* AVUTIL_AVSTRING_H */