1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-07 12:30:27 +00:00

Merge pull request #95613 from timothyqiu/split-empty

Fix `split_floats` behavior when spaces are used as separators
This commit is contained in:
Rémi Verschelde
2024-08-16 14:36:40 +02:00
2 changed files with 82 additions and 50 deletions

View File

@@ -1537,13 +1537,16 @@ Vector<double> 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_float(&get_data()[from]));
buffer[end] = 0;
ret.push_back(String::to_float(&buffer.get_data()[from]));
buffer[end] = _cowdata.get(end);
}
if (end == len) {
@@ -1561,6 +1564,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);
@@ -1572,7 +1576,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_float(&get_data()[from]));
buffer[end] = 0;
ret.push_back(String::to_float(&buffer.get_data()[from]));
buffer[end] = _cowdata.get(end);
}
if (end == len) {