MCPcopy Create free account
hub / github.com/defold/defold / dmStrTok

Function dmStrTok

engine/dlib/src/dlib/dstrings.cpp:75–123  ·  view source on GitHub ↗

* thread-save version of strtok */

Source from the content-addressed store, hash-verified

73 * thread-save version of strtok
74 */
75char* dmStrTok(char *s, const char *delim, char **lasts)
76{
77 const char *spanp;
78 int c, sc;
79 char *tok;
80
81 /* s may be NULL */
82 assert(delim != NULL);
83 assert(lasts != NULL);
84
85 if (s == NULL && (s = *lasts) == NULL)
86 return (NULL);
87
88 /*
89 * Skip (span) leading delimiters (s += strspn(s, delim), sort of).
90 */
91cont:
92 c = *s++;
93 for (spanp = delim; (sc = *spanp++) != 0;) {
94 if (c == sc)
95 goto cont;
96 }
97
98 if (c == 0) { /* no non-delimiter characters */
99 *lasts = NULL;
100 return (NULL);
101 }
102 tok = s - 1;
103
104 /*
105 * Scan token (scan for delimiters: s += strcspn(s, delim), sort of).
106 * Note that delim must have one NUL; we stop if we see that, too.
107 */
108 for (;;) {
109 c = *s++;
110 spanp = delim;
111 do {
112 if ((sc = *spanp++) == c) {
113 if (c == 0)
114 s = NULL;
115 else
116 s[-1] = 0;
117 *lasts = s;
118 return (tok);
119 }
120 } while (sc != 0);
121 }
122 /* NOTREACHED */
123}
124
125/* $NetBSD: strlcpy.c,v 1.5 1999/09/20 04:39:47 lukem Exp $ */
126/* from OpenBSD: strlcpy.c,v 1.4 1999/05/01 18:56:41 millert Exp */

Callers 11

LaunchFunction · 0.85
HttpWriteHeadersFunction · 0.85
ParseHeaderFunction · 0.85
ParseHeaderFunction · 0.85
TESTFunction · 0.85
LoadDebugInitScriptsFunction · 0.85
engine.cppFile · 0.85
ParsePostUrlMethod · 0.85
HttpResponseDecoderFunction · 0.85
StoreExtensionsFunction · 0.85
ParseStacktraceLineFunction · 0.85

Calls 1

assertFunction · 0.50

Tested by 1

TESTFunction · 0.68