| 1038 | } |
| 1039 | |
| 1040 | Vector<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 | |
| 1088 | Vector<String> String::split(const char *p_splitter, bool p_allow_empty, int p_maxsplit) const { |
| 1089 | Vector<String> ret; |