| 892 | } |
| 893 | |
| 894 | void String::splitCb( std::function<bool( std::string_view )> fnCb, const std::string& str, |
| 895 | const std::string& delims, const std::string& delimsPreserve, |
| 896 | const std::string& quote, const bool& removeQuotes ) { |
| 897 | if ( str.empty() || ( delims.empty() && delimsPreserve.empty() ) ) |
| 898 | return; |
| 899 | |
| 900 | std::string allDelims = delims + delimsPreserve + quote; |
| 901 | |
| 902 | std::string::size_type tokenStart = 0; |
| 903 | std::string::size_type tokenEnd = str.find_first_of( allDelims, tokenStart ); |
| 904 | std::string::size_type tokenLen = 0; |
| 905 | std::string_view token; |
| 906 | while ( true ) { |
| 907 | bool fromQuote = false; |
| 908 | while ( tokenEnd != std::string::npos && |
| 909 | quote.find_first_of( str[tokenEnd] ) != std::string::npos ) { |
| 910 | if ( str[tokenEnd] == '(' ) { |
| 911 | tokenEnd = findCloseBracket( str, tokenEnd, '(', ')' ); |
| 912 | } else if ( str[tokenEnd] == '[' ) { |
| 913 | tokenEnd = findCloseBracket( str, tokenEnd, '[', ']' ); |
| 914 | } else if ( str[tokenEnd] == '{' ) { |
| 915 | tokenEnd = findCloseBracket( str, tokenEnd, '{', '}' ); |
| 916 | } else { |
| 917 | fromQuote = true; |
| 918 | tokenEnd = str.find_first_of( str[tokenEnd], tokenEnd + 1 ); |
| 919 | } |
| 920 | if ( tokenEnd != std::string::npos ) { |
| 921 | tokenEnd = str.find_first_of( allDelims, tokenEnd + 1 ); |
| 922 | } |
| 923 | } |
| 924 | |
| 925 | if ( tokenEnd == std::string::npos ) { |
| 926 | tokenLen = std::string::npos; |
| 927 | } else { |
| 928 | tokenLen = tokenEnd - tokenStart; |
| 929 | } |
| 930 | |
| 931 | token = std::string_view{ str }.substr( tokenStart, tokenLen ); |
| 932 | if ( !token.empty() ) { |
| 933 | if ( fromQuote && removeQuotes && token.size() > 2 ) |
| 934 | token = token.substr( 1, token.size() - 2 ); |
| 935 | if ( !fnCb( token ) ) |
| 936 | return; |
| 937 | } |
| 938 | if ( tokenEnd != std::string::npos && !delimsPreserve.empty() && |
| 939 | delimsPreserve.find_first_of( str[tokenEnd] ) != std::string::npos ) { |
| 940 | if ( !fnCb( std::string_view{ str }.substr( tokenEnd, 1 ) ) ) |
| 941 | return; |
| 942 | } |
| 943 | |
| 944 | tokenStart = tokenEnd; |
| 945 | if ( tokenStart == std::string::npos ) |
| 946 | break; |
| 947 | tokenStart++; |
| 948 | if ( tokenStart == str.length() ) |
| 949 | break; |
| 950 | tokenEnd = str.find_first_of( allDelims, tokenStart ); |
| 951 | } |
nothing calls this directly
no test coverage detected