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

Method get_slice

core/string/ustring.cpp:888–926  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

886}
887
888String 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
928String String::get_slice(const char *p_splitter, int p_slice) const {
929 if (is_empty() || p_splitter == nullptr || *p_splitter == '\0') {

Callers 15

find_classMethod · 0.80
has_classMethod · 0.80
load_source_codeMethod · 0.80
find_classMethod · 0.80
has_classMethod · 0.80
reload_scriptsMethod · 0.80
ConfigMethod · 0.80
save_resourceMethod · 0.80
_edit_currentMethod · 0.80
edit_foreign_resourceMethod · 0.80

Calls 4

findFunction · 0.85
strlenFunction · 0.85
is_emptyMethod · 0.45
lengthMethod · 0.45

Tested by 1

set_objectsMethod · 0.64