| 1135 | } |
| 1136 | |
| 1137 | Vector<String> String::rsplit(const String &p_splitter, bool p_allow_empty, int p_maxsplit) const { |
| 1138 | Vector<String> ret; |
| 1139 | const int len = length(); |
| 1140 | int remaining_len = len; |
| 1141 | |
| 1142 | while (true) { |
| 1143 | if (remaining_len < p_splitter.length() || (p_maxsplit > 0 && p_maxsplit == ret.size())) { |
| 1144 | // no room for another splitter or hit max splits, push what's left and we're done |
| 1145 | if (p_allow_empty || remaining_len > 0) { |
| 1146 | ret.push_back(substr(0, remaining_len)); |
| 1147 | } |
| 1148 | break; |
| 1149 | } |
| 1150 | |
| 1151 | int left_edge; |
| 1152 | if (p_splitter.is_empty()) { |
| 1153 | left_edge = remaining_len - 1; |
| 1154 | if (left_edge == 0) { |
| 1155 | left_edge--; // Skip to the < 0 condition. |
| 1156 | } |
| 1157 | } else { |
| 1158 | left_edge = rfind(p_splitter, remaining_len - p_splitter.length()); |
| 1159 | } |
| 1160 | |
| 1161 | if (left_edge < 0) { |
| 1162 | // no more splitters, we're done |
| 1163 | ret.push_back(substr(0, remaining_len)); |
| 1164 | break; |
| 1165 | } |
| 1166 | |
| 1167 | int substr_start = left_edge + p_splitter.length(); |
| 1168 | if (p_allow_empty || substr_start < remaining_len) { |
| 1169 | ret.push_back(substr(substr_start, remaining_len - substr_start)); |
| 1170 | } |
| 1171 | |
| 1172 | remaining_len = left_edge; |
| 1173 | } |
| 1174 | |
| 1175 | ret.reverse(); |
| 1176 | return ret; |
| 1177 | } |
| 1178 | |
| 1179 | Vector<String> String::rsplit(const char *p_splitter, bool p_allow_empty, int p_maxsplit) const { |
| 1180 | Vector<String> ret; |
no test coverage detected