Fix split_floats behavior when spaces are used as separators

This commit is contained in:
Haoyu Qiu
2024-08-19 15:14:10 +08:00
parent b58d16f0b8
commit a808f3e877
2 changed files with 70 additions and 2 deletions

View File

@@ -904,13 +904,16 @@ Vector<float> String::split_floats(const String &p_splitter, bool p_allow_empty)
int from = 0;
int len = length();
String buffer = *this;
while (true) {
int end = find(p_splitter, from);
if (end < 0) {
end = len;
}
if (p_allow_empty || (end > from)) {
ret.push_back(String::to_double(&c_str()[from]));
buffer[end] = 0;
ret.push_back(String::to_double(&buffer.c_str()[from]));
buffer[end] = _cowdata.get(end);
}
if (end == len) {
@@ -928,6 +931,7 @@ Vector<float> String::split_floats_mk(const Vector<String> &p_splitters, bool p_
int from = 0;
int len = length();
String buffer = *this;
while (true) {
int idx;
int end = findmk(p_splitters, from, &idx);
@@ -939,7 +943,9 @@ Vector<float> String::split_floats_mk(const Vector<String> &p_splitters, bool p_
}
if (p_allow_empty || (end > from)) {
ret.push_back(String::to_double(&c_str()[from]));
buffer[end] = 0;
ret.push_back(String::to_double(&buffer.c_str()[from]));
buffer[end] = _cowdata.get(end);
}
if (end == len) {