From: Stefano Sabatini <[email protected]>
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.
---
doc/APIchanges | 3 +++
libavutil/avstring.c | 29 +++++++++++++++++++++++++++++
libavutil/avstring.h | 24 ++++++++++++++++++++++++
libavutil/version.h | 2 +-
4 files changed, 57 insertions(+), 1 deletion(-)
diff --git a/doc/APIchanges b/doc/APIchanges
index f8ce3b0..1bb9f1c 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -13,6 +13,9 @@ libavutil: 2013-12-xx
API changes, most recent first:
+2014-03-xx - xxxxxxx - lavu 53.07.0 - avstring.h
+ Add av_strtok().
+
2014-03-xx - xxxxxxx - lavu 53.06.0 - avstring.h
Add av_asprintf().
diff --git a/libavutil/avstring.c b/libavutil/avstring.c
index a292731..edcb511 100644
--- a/libavutil/avstring.c
+++ b/libavutil/avstring.c
@@ -260,6 +260,35 @@ int av_isxdigit(int c)
return av_isdigit(c) || (c >= 'a' && c <= 'f');
}
+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
int main(void)
diff --git a/libavutil/avstring.h b/libavutil/avstring.h
index 4789cd5..33b9cdc 100644
--- a/libavutil/avstring.h
+++ b/libavutil/avstring.h
@@ -233,4 +233,28 @@ const char *av_dirname(char *path);
* @}
*/
+/**
+ * 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 */
diff --git a/libavutil/version.h b/libavutil/version.h
index 36070b2..d680979 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -54,7 +54,7 @@
*/
#define LIBAVUTIL_VERSION_MAJOR 53
-#define LIBAVUTIL_VERSION_MINOR 6
+#define LIBAVUTIL_VERSION_MINOR 7
#define LIBAVUTIL_VERSION_MICRO 0
#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
--
1.9.0
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel