MCPcopy Create free account
hub / github.com/albertodemichelis/squirrel / _string_split

Function _string_split

sqstdlib/sqstdstring.cpp:249–286  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

247}
248
249static SQInteger _string_split(HSQUIRRELVM v)
250{
251 const SQChar *str,*seps;
252 SQInteger sepsize;
253 SQBool skipempty = SQFalse;
254 sq_getstring(v,2,&str);
255 sq_getstringandsize(v,3,&seps,&sepsize);
256 if(sepsize == 0) return sq_throwerror(v,_SC("empty separators string"));
257 if(sq_gettop(v)>3) {
258 sq_getbool(v,4,&skipempty);
259 }
260 const SQChar *start = str;
261 const SQChar *end = str;
262 sq_newarray(v,0);
263 while(*end != '\0')
264 {
265 SQChar cur = *end;
266 for(SQInteger i = 0; i < sepsize; i++)
267 {
268 if(cur == seps[i])
269 {
270 if(!skipempty || (end != start)) {
271 sq_pushstring(v,start,end-start);
272 sq_arrayappend(v,-2);
273 }
274 start = end + 1;
275 break;
276 }
277 }
278 end++;
279 }
280 if(end != start)
281 {
282 sq_pushstring(v,start,end-start);
283 sq_arrayappend(v,-2);
284 }
285 return 1;
286}
287
288static SQInteger _string_escape(HSQUIRRELVM v)
289{

Callers

nothing calls this directly

Calls 8

sq_getstringFunction · 0.85
sq_getstringandsizeFunction · 0.85
sq_throwerrorFunction · 0.85
sq_gettopFunction · 0.85
sq_getboolFunction · 0.85
sq_newarrayFunction · 0.85
sq_pushstringFunction · 0.85
sq_arrayappendFunction · 0.85

Tested by

no test coverage detected