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

Method split

core/string/ustring.cpp:1040–1086  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1038}
1039
1040Vector<String> String::split(const String &p_splitter, bool p_allow_empty, int p_maxsplit) const {
1041 Vector<String> ret;
1042
1043 if (is_empty()) {
1044 if (p_allow_empty) {
1045 ret.push_back("");
1046 }
1047 return ret;
1048 }
1049
1050 int from = 0;
1051 int len = length();
1052
1053 while (true) {
1054 int end;
1055 if (p_splitter.is_empty()) {
1056 end = from + 1;
1057 } else {
1058 end = find(p_splitter, from);
1059 if (end < 0) {
1060 end = len;
1061 }
1062 }
1063 if (p_allow_empty || (end > from)) {
1064 if (p_maxsplit <= 0) {
1065 ret.push_back(substr(from, end - from));
1066 } else {
1067 // Put rest of the string and leave cycle.
1068 if (p_maxsplit == ret.size()) {
1069 ret.push_back(substr(from, len));
1070 break;
1071 }
1072
1073 // Otherwise, push items until positive limit is reached.
1074 ret.push_back(substr(from, end - from));
1075 }
1076 }
1077
1078 if (end == len) {
1079 break;
1080 }
1081
1082 from = end + p_splitter.length();
1083 }
1084
1085 return ret;
1086}
1087
1088Vector<String> String::split(const char *p_splitter, bool p_allow_empty, int p_maxsplit) const {
1089 Vector<String> ret;

Callers 15

DecodeQueryMethod · 0.95
parsePinPatternsMethod · 0.95
ver_parseFunction · 0.80
get_version_infoFunction · 0.80
get_git_infoFunction · 0.80
is_apple_clangFunction · 0.80
get_compiler_versionFunction · 0.80
glob_recursive_2Function · 0.80
_set_object_propertyMethod · 0.80
_setMethod · 0.80
_getMethod · 0.80

Calls 6

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

Tested by 10

strip_warningsFunction · 0.64
read_testsFunction · 0.64
update_treeMethod · 0.64
_property_path_matchesFunction · 0.64
update_category_listMethod · 0.64
_load_resourceMethod · 0.64
load_test_dataFunction · 0.64
compact_spacesFunction · 0.64