From e791f4fce275247a66eb657ff7cc7be4ffd4d5bc Mon Sep 17 00:00:00 2001 From: Micky Date: Sun, 20 Nov 2022 12:29:50 +0100 Subject: Double precision of `String.split_floats` --- core/string/ustring.cpp | 4 ++-- core/string/ustring.h | 2 +- doc/classes/String.xml | 2 +- editor/editor_help.cpp | 2 +- editor/plugins/script_text_editor.cpp | 2 +- tests/core/string/test_string.h | 19 ++++++++++--------- 6 files changed, 16 insertions(+), 15 deletions(-) diff --git a/core/string/ustring.cpp b/core/string/ustring.cpp index 8993f9667d..175c42542b 100644 --- a/core/string/ustring.cpp +++ b/core/string/ustring.cpp @@ -1256,8 +1256,8 @@ Vector String::rsplit(const String &p_splitter, bool p_allow_empty, int return ret; } -Vector String::split_floats(const String &p_splitter, bool p_allow_empty) const { - Vector ret; +Vector String::split_floats(const String &p_splitter, bool p_allow_empty) const { + Vector ret; int from = 0; int len = length(); diff --git a/core/string/ustring.h b/core/string/ustring.h index 8af74584f3..0c171024f7 100644 --- a/core/string/ustring.h +++ b/core/string/ustring.h @@ -348,7 +348,7 @@ public: Vector split(const String &p_splitter = "", bool p_allow_empty = true, int p_maxsplit = 0) const; Vector rsplit(const String &p_splitter = "", bool p_allow_empty = true, int p_maxsplit = 0) const; Vector split_spaces() const; - Vector split_floats(const String &p_splitter, bool p_allow_empty = true) const; + Vector split_floats(const String &p_splitter, bool p_allow_empty = true) const; Vector split_floats_mk(const Vector &p_splitters, bool p_allow_empty = true) const; Vector split_ints(const String &p_splitter, bool p_allow_empty = true) const; Vector split_ints_mk(const Vector &p_splitters, bool p_allow_empty = true) const; diff --git a/doc/classes/String.xml b/doc/classes/String.xml index 999913b1ac..53040b2753 100644 --- a/doc/classes/String.xml +++ b/doc/classes/String.xml @@ -738,7 +738,7 @@ - + diff --git a/editor/editor_help.cpp b/editor/editor_help.cpp index 0a443ee645..636e076b1e 100644 --- a/editor/editor_help.cpp +++ b/editor/editor_help.cpp @@ -1363,7 +1363,7 @@ void EditorHelp::_update_doc() { if (constants[i].value.begins_with("Color(") && constants[i].value.ends_with(")")) { String stripped = constants[i].value.replace(" ", "").replace("Color(", "").replace(")", ""); - Vector color = stripped.split_floats(","); + PackedFloat64Array color = stripped.split_floats(","); if (color.size() >= 3) { class_desc->push_color(Color(color[0], color[1], color[2])); _add_bulletpoint(); diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp index 0d12d07aa7..4e66dc3d7e 100644 --- a/editor/plugins/script_text_editor.cpp +++ b/editor/plugins/script_text_editor.cpp @@ -1860,7 +1860,7 @@ void ScriptTextEditor::_text_edit_gui_input(const Ref &ev) { if (valid) { color_args = line.substr(begin, end - begin); String stripped = color_args.replace(" ", "").replace("(", "").replace(")", ""); - Vector color = stripped.split_floats(","); + PackedFloat64Array color = stripped.split_floats(","); if (color.size() > 2) { float alpha = color.size() > 3 ? color[3] : 1.0f; color_picker->set_pick_color(Color(color[0], color[1], color[2], alpha)); diff --git a/tests/core/string/test_string.h b/tests/core/string/test_string.h index 7e4e3aa9f0..ebb526b37c 100644 --- a/tests/core/string/test_string.h +++ b/tests/core/string/test_string.h @@ -516,21 +516,22 @@ TEST_CASE("[String] Splitting") { s = "1.2;2.3 4.5"; const double slices_d[3] = { 1.2, 2.3, 4.5 }; - Vector f; - f = s.split_floats(";"); - CHECK(f.size() == 2); - for (int i = 0; i < f.size(); i++) { - CHECK(ABS(f[i] - slices_d[i]) <= 0.00001); + Vector d_arr; + d_arr = s.split_floats(";"); + CHECK(d_arr.size() == 2); + for (int i = 0; i < d_arr.size(); i++) { + CHECK(ABS(d_arr[i] - slices_d[i]) <= 0.00001); } Vector keys; keys.push_back(";"); keys.push_back(" "); - f = s.split_floats_mk(keys); - CHECK(f.size() == 3); - for (int i = 0; i < f.size(); i++) { - CHECK(ABS(f[i] - slices_d[i]) <= 0.00001); + Vector f_arr; + f_arr = s.split_floats_mk(keys); + CHECK(f_arr.size() == 3); + for (int i = 0; i < f_arr.size(); i++) { + CHECK(ABS(f_arr[i] - slices_d[i]) <= 0.00001); } s = "1;2 4"; -- cgit v1.2.3