MCPcopy Create free account
hub / github.com/Redot-Engine/redot-engine / rsplit

Method rsplit

core/string/ustring.cpp:1137–1177  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1135}
1136
1137Vector<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
1179Vector<String> String::rsplit(const char *p_splitter, bool p_allow_empty, int p_maxsplit) const {
1180 Vector<String> ret;

Callers 5

_get_propertyMethod · 0.80
is_property_validMethod · 0.80
_animation_duplicateMethod · 0.80
parse_propertyMethod · 0.80
detect_build_env_archFunction · 0.80

Calls 6

strlenFunction · 0.85
sizeMethod · 0.65
lengthMethod · 0.45
push_backMethod · 0.45
is_emptyMethod · 0.45
reverseMethod · 0.45

Tested by

no test coverage detected