From 49403cbfa0399bb4284ea5c36cc90216a0bda6ff Mon Sep 17 00:00:00 2001 From: Nathan Franke Date: Thu, 9 Dec 2021 03:42:46 -0600 Subject: Replace String comparisons with "", String() to is_empty() Also: - Adds two stress tests to test_string.h - Changes to .empty() on std::strings --- modules/fbx/data/fbx_material.cpp | 8 +++---- modules/fbx/fbx_parser/FBXMeshGeometry.cpp | 2 +- modules/gdnative/nativescript/api_generator.cpp | 2 +- modules/gdnative/nativescript/nativescript.cpp | 2 +- .../gdnative/pluginscript/pluginscript_script.cpp | 7 +++--- modules/gdnative/pluginscript/register_types.cpp | 6 ++--- modules/gdscript/editor/gdscript_highlighter.cpp | 6 ++--- modules/gdscript/gdscript.cpp | 22 +++++++++--------- modules/gdscript/gdscript_cache.cpp | 6 ++--- modules/gdscript/gdscript_compiler.cpp | 8 +++---- modules/gdscript/gdscript_editor.cpp | 4 ++-- modules/gdscript/gdscript_parser.cpp | 4 ++-- modules/gdscript/gdscript_vm.cpp | 20 ++++++++--------- modules/gdscript/tests/gdscript_test_runner.cpp | 2 +- modules/glslang/register_types.cpp | 2 +- modules/gridmap/grid_map_editor_plugin.cpp | 4 ++-- modules/hdr/image_loader_hdr.cpp | 2 +- modules/mbedtls/crypto_mbedtls.cpp | 2 +- modules/mono/editor/code_completion.cpp | 2 +- modules/text_server_adv/text_server_adv.cpp | 14 ++++++------ .../visual_script/editor/visual_script_editor.cpp | 18 +++++++-------- .../editor/visual_script_property_selector.cpp | 16 ++++++------- modules/visual_script/visual_script.cpp | 8 +++---- .../visual_script/visual_script_flow_control.cpp | 8 +++---- modules/visual_script/visual_script_func_nodes.cpp | 26 +++++++++++----------- modules/visual_script/visual_script_nodes.cpp | 16 ++++++------- .../visual_script/visual_script_yield_nodes.cpp | 2 +- modules/websocket/wsl_server.cpp | 6 ++--- 28 files changed, 112 insertions(+), 113 deletions(-) (limited to 'modules') diff --git a/modules/fbx/data/fbx_material.cpp b/modules/fbx/data/fbx_material.cpp index 86baec4244..26c9ef8d54 100644 --- a/modules/fbx/data/fbx_material.cpp +++ b/modules/fbx/data/fbx_material.cpp @@ -60,7 +60,7 @@ String find_file(const String &p_base, const String &p_file_to_find) { dir.list_dir_begin(); String n = dir.get_next(); - while (n != String()) { + while (!n.is_empty()) { if (n == "." || n == "..") { n = dir.get_next(); continue; @@ -68,7 +68,7 @@ String find_file(const String &p_base, const String &p_file_to_find) { if (dir.current_is_dir()) { // Don't use `path_to` or the returned path will be wrong. const String f = find_file(p_base + "/" + n, p_file_to_find); - if (f != "") { + if (!f.is_empty()) { return f; } } else if (n == p_file_to_find) { @@ -119,7 +119,7 @@ String FBXMaterial::find_texture_path_by_filename(const String p_filename, const dir.open("res://"); dir.list_dir_begin(); String n = dir.get_next(); - while (n != String()) { + while (!n.is_empty()) { if (n == "." || n == "..") { n = dir.get_next(); continue; @@ -136,7 +136,7 @@ String FBXMaterial::find_texture_path_by_filename(const String p_filename, const lower_n.find("picture") >= 0) { // Don't use `path_to` or the returned path will be wrong. const String f = find_file(String("res://") + n, p_filename); - if (f != "") { + if (!f.is_empty()) { return f; } } diff --git a/modules/fbx/fbx_parser/FBXMeshGeometry.cpp b/modules/fbx/fbx_parser/FBXMeshGeometry.cpp index 2cc25a0690..2bb634ea56 100644 --- a/modules/fbx/fbx_parser/FBXMeshGeometry.cpp +++ b/modules/fbx/fbx_parser/FBXMeshGeometry.cpp @@ -368,7 +368,7 @@ MeshGeometry::MappingData MeshGeometry::resolve_vertex_data_array( // UVIndex, MaterialIndex, NormalIndex, etc.. std::string indexDataElementName; - if (indexOverride != "") { + if (!indexOverride.empty()) { // Colors should become ColorIndex indexDataElementName = indexOverride; } else { diff --git a/modules/gdnative/nativescript/api_generator.cpp b/modules/gdnative/nativescript/api_generator.cpp index 598f7c7ad0..ae16c22849 100644 --- a/modules/gdnative/nativescript/api_generator.cpp +++ b/modules/gdnative/nativescript/api_generator.cpp @@ -397,7 +397,7 @@ List generate_c_api_classes() { arg_type = "Variant"; } else if (arg_info.type == Variant::OBJECT) { arg_type = arg_info.class_name; - if (arg_type == "") { + if (arg_type.is_empty()) { arg_type = Variant::get_type_name(arg_info.type); } } else { diff --git a/modules/gdnative/nativescript/nativescript.cpp b/modules/gdnative/nativescript/nativescript.cpp index 368eb67fa6..075977b60f 100644 --- a/modules/gdnative/nativescript/nativescript.cpp +++ b/modules/gdnative/nativescript/nativescript.cpp @@ -682,7 +682,7 @@ void NativeScriptInstance::get_property_list(List *p_properties) c ERR_CONTINUE(info.type < 0 || info.type >= Variant::VARIANT_MAX); info.name = d["name"]; - ERR_CONTINUE(info.name == ""); + ERR_CONTINUE(info.name.is_empty()); if (d.has("hint")) { info.hint = PropertyHint(d["hint"].operator int64_t()); diff --git a/modules/gdnative/pluginscript/pluginscript_script.cpp b/modules/gdnative/pluginscript/pluginscript_script.cpp index 04a293ddbd..5bda9e1d53 100644 --- a/modules/gdnative/pluginscript/pluginscript_script.cpp +++ b/modules/gdnative/pluginscript/pluginscript_script.cpp @@ -232,8 +232,7 @@ bool PluginScript::instance_has(const Object *p_this) const { } bool PluginScript::has_source_code() const { - bool has = _source != ""; - return has; + return !_source.is_empty(); } String PluginScript::get_source_code() const { @@ -257,11 +256,11 @@ Error PluginScript::reload(bool p_keep_state) { _valid = false; String basedir = _path; - if (basedir == "") { + if (basedir.is_empty()) { basedir = get_path(); } - if (basedir != "") { + if (!basedir.is_empty()) { basedir = basedir.get_base_dir(); } diff --git a/modules/gdnative/pluginscript/register_types.cpp b/modules/gdnative/pluginscript/register_types.cpp index 7faacfdcb9..c4fbff69f0 100644 --- a/modules/gdnative/pluginscript/register_types.cpp +++ b/modules/gdnative/pluginscript/register_types.cpp @@ -44,9 +44,9 @@ static List pluginscript_languages; static Error _check_language_desc(const godot_pluginscript_language_desc *desc) { - ERR_FAIL_COND_V(!desc->name || desc->name == String(), ERR_BUG); - ERR_FAIL_COND_V(!desc->type || desc->type == String(), ERR_BUG); - ERR_FAIL_COND_V(!desc->extension || desc->extension == String(), ERR_BUG); + ERR_FAIL_COND_V(!desc->name, ERR_BUG); + ERR_FAIL_COND_V(!desc->type, ERR_BUG); + ERR_FAIL_COND_V(!desc->extension, ERR_BUG); ERR_FAIL_COND_V(!desc->recognized_extensions || !desc->recognized_extensions[0], ERR_BUG); ERR_FAIL_COND_V(!desc->init, ERR_BUG); ERR_FAIL_COND_V(!desc->finish, ERR_BUG); diff --git a/modules/gdscript/editor/gdscript_highlighter.cpp b/modules/gdscript/editor/gdscript_highlighter.cpp index 6529154e5c..4f711dfd1e 100644 --- a/modules/gdscript/editor/gdscript_highlighter.cpp +++ b/modules/gdscript/editor/gdscript_highlighter.cpp @@ -413,7 +413,7 @@ Dictionary GDScriptSyntaxHighlighter::_get_line_syntax_highlighting_impl(int p_l previous_column = j; // ignore if just whitespace - if (text != "") { + if (!text.is_empty()) { previous_text = text; } } @@ -509,7 +509,7 @@ void GDScriptSyntaxHighlighter::_update_cache() { for (const String &comment : comments) { String beg = comment.get_slice(" ", 0); String end = comment.get_slice_count(" ") > 1 ? comment.get_slice(" ", 1) : String(); - add_color_region(beg, end, comment_color, end == ""); + add_color_region(beg, end, comment_color, end.is_empty()); } /* Strings */ @@ -519,7 +519,7 @@ void GDScriptSyntaxHighlighter::_update_cache() { for (const String &string : strings) { String beg = string.get_slice(" ", 0); String end = string.get_slice_count(" ") > 1 ? string.get_slice(" ", 1) : String(); - add_color_region(beg, end, string_color, end == ""); + add_color_region(beg, end, string_color, end.is_empty()); } const Ref