MCPcopy Create free account
hub / github.com/GaijinEntertainment/daScript / builtin_string_split

Function builtin_string_split

src/builtin/module_builtin_string.cpp:566–600  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

564 }
565
566 void builtin_string_split ( const char * str, const char * delim, const Block & block, Context * context, LineInfoArg * at ) {
567 if ( !str ) str = "";
568 if ( !delim ) delim = "";
569 vector<const char *> tokens;
570 vector<string> words;
571 const char * ch = str;
572 auto delimLen = stringLengthSafe(*context,delim);
573 if ( delimLen ) {
574 while ( *ch ) {
575 const char * tok = ch;
576 while ( *ch && strncmp(delim,ch,delimLen)!=0 ) ch++;
577 words.push_back(string(tok,ch-tok));
578 if ( !*ch ) break;
579 if ( strncmp(delim,ch,delimLen)==0 ) ch+=delimLen;
580 if ( !*ch ) words.push_back("");
581 }
582 } else {
583 auto len = stringLengthSafe(*context,str);
584 words.reserve(len);
585 while ( *ch ) {
586 words.push_back(string(1,*ch));
587 ch ++;
588 }
589 }
590 tokens.reserve(words.size());
591 for ( auto & tok : words ) {
592 tokens.push_back(tok.c_str());
593 }
594 if ( tokens.empty() ) tokens.push_back("");
595 Array arr;
596 array_mark_locked(arr, (char *)tokens.data(), uint32_t(tokens.size()));
597 vec4f args[1];
598 args[0] = cast<Array *>::from(&arr);
599 context->invoke(block, args, nullptr, at);
600 }
601
602 char * builtin_string_replace ( const char * str, const char * toSearch, const char * replaceStr, Context * context, LineInfoArg * at ) {
603 auto toSearchSize = stringLengthSafe(*context, toSearch);

Callers

nothing calls this directly

Calls 10

stringLengthSafeFunction · 0.85
stringClass · 0.85
array_mark_lockedFunction · 0.85
push_backMethod · 0.45
reserveMethod · 0.45
sizeMethod · 0.45
c_strMethod · 0.45
emptyMethod · 0.45
dataMethod · 0.45
invokeMethod · 0.45

Tested by

no test coverage detected