diff options
author | Haoyu Qiu <timothyqiu32@gmail.com> | 2024-08-16 13:23:04 +0800 |
---|---|---|
committer | Haoyu Qiu <timothyqiu32@gmail.com> | 2024-08-16 17:30:44 +0800 |
commit | f483c3aafa5f3cfb1ab763ab4eb077aac74e88d6 (patch) | |
tree | 97de61b3479cb57c212e668644cf46cf7a052bac /core/string | |
parent | a7598679cff6daffbec8f16314b853d87268fff5 (diff) | |
download | redot-engine-f483c3aafa5f3cfb1ab763ab4eb077aac74e88d6.tar.gz |
Fix split_floats behavior when spaces are used as separators
Diffstat (limited to 'core/string')
-rw-r--r-- | core/string/ustring.cpp | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/core/string/ustring.cpp b/core/string/ustring.cpp index cf19a1d48f..36f1b6b65e 100644 --- a/core/string/ustring.cpp +++ b/core/string/ustring.cpp @@ -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) { |