Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Montagne <montagne29@wanadoo.fr>2011-10-28 17:07:11 +0400
committerBastien Montagne <montagne29@wanadoo.fr>2011-10-28 17:07:11 +0400
commit2ed7a66653c9c94cb47064cb12092c2e81331b9b (patch)
treefd74c9e051fb00c941a3d474d48a5655919ab140 /source/blender/blenlib/BLI_string.h
parent0d63bb005ff7c45ca0ebcfbe4eaf1215dfe2d3e2 (diff)
BLI_string: Adding the BLI_strtok_r function, which mimics stdlib strtok_r (unavailable on some systems).
It allows to iterate over a string, returning an new element each time, using a char as separator. See BLI_String.h's comments for more info and an example. Needed by the UI template list patch following!
Diffstat (limited to 'source/blender/blenlib/BLI_string.h')
-rw-r--r--source/blender/blenlib/BLI_string.h22
1 files changed, 22 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_string.h b/source/blender/blenlib/BLI_string.h
index 0cdb573c4c6..9a7fa521af1 100644
--- a/source/blender/blenlib/BLI_string.h
+++ b/source/blender/blenlib/BLI_string.h
@@ -133,6 +133,28 @@ int BLI_strncasecmp(const char *s1, const char *s2, size_t len);
int BLI_natstrcmp(const char *s1, const char *s2);
size_t BLI_strnlen(const char *str, size_t maxlen);
+ /**
+ * Split str on the first occurence of delimiter, returns the first
+ * part as a mallocN'd string, and stores the second part into
+ * ctx (also mallocN'd).
+ * If str is NULL, split on ctx instead.
+ * This allows to iterate over this "generator" function:
+ *
+ * char *ctx = NULL;
+ * char *res = NULL;
+ * for(res = BLI_strtok_r("a;dummy;csv;line", ";", &ctx); res; res = BLI_strtok_r(NULL, ";", &ctx)) {
+ * printf(res);
+ * MEM_freeN(res);
+ * }
+ *
+ * @param str The string to be split.
+ * @param delimiter The char used to split str apart.
+ * @param ctx The "context" string. It’s a pointer inside the org passed @str,
+ * so it has no specific mem management.
+ * @retval Returns the mallocN'd first element from split str (or ctx).
+ */
+char *BLI_strtok_r(char *str, const char *delimiter, char **ctx);
+
void BLI_timestr(double _time, char *str); /* time var is global */
void BLI_ascii_strtolower(char *str, int len);