| 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); |
nothing calls this directly
no test coverage detected