| 886 | } |
| 887 | |
| 888 | String String::get_slice(const String &p_splitter, int p_slice) const { |
| 889 | if (is_empty() || p_splitter.is_empty()) { |
| 890 | return ""; |
| 891 | } |
| 892 | |
| 893 | int pos = 0; |
| 894 | int prev_pos = 0; |
| 895 | //int slices=1; |
| 896 | if (p_slice < 0) { |
| 897 | return ""; |
| 898 | } |
| 899 | if (find(p_splitter) == -1) { |
| 900 | return *this; |
| 901 | } |
| 902 | |
| 903 | int i = 0; |
| 904 | while (true) { |
| 905 | pos = find(p_splitter, pos); |
| 906 | if (pos == -1) { |
| 907 | pos = length(); //reached end |
| 908 | } |
| 909 | |
| 910 | int from = prev_pos; |
| 911 | //int to=pos; |
| 912 | |
| 913 | if (p_slice == i) { |
| 914 | return substr(from, pos - from); |
| 915 | } |
| 916 | |
| 917 | if (pos == length()) { //reached end and no find |
| 918 | break; |
| 919 | } |
| 920 | pos += p_splitter.length(); |
| 921 | prev_pos = pos; |
| 922 | i++; |
| 923 | } |
| 924 | |
| 925 | return ""; //no find! |
| 926 | } |
| 927 | |
| 928 | String String::get_slice(const char *p_splitter, int p_slice) const { |
| 929 | if (is_empty() || p_splitter == nullptr || *p_splitter == '\0') { |