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 --- main/main.cpp | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) (limited to 'main') diff --git a/main/main.cpp b/main/main.cpp index c7b33f3f1b..6cc877f8c2 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -423,7 +423,7 @@ Error Main::test_setup() { register_server_types(); translation_server->setup(); //register translations, load them, etc. - if (locale != "") { + if (!locale.is_empty()) { translation_server->set_locale(locale); } translation_server->load_translations(); @@ -1122,7 +1122,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph // Network file system needs to be configured before globals, since globals are based on the // 'project.godot' file which will only be available through the network if this is enabled FileAccessNetwork::configure(); - if (remotefs != "") { + if (!remotefs.is_empty()) { file_access_network_client = memnew(FileAccessNetworkClient); int port; if (remotefs.find(":") != -1) { @@ -1289,7 +1289,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph PROPERTY_HINT_ENUM, "vulkan,opengl3")); // if not set on the command line - if (rendering_driver == "") { + if (rendering_driver.is_empty()) { rendering_driver = GLOBAL_GET("rendering/driver/driver_name"); } @@ -1419,7 +1419,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph OS::get_singleton()->set_display_driver_id(display_driver_idx); GLOBAL_DEF_RST_NOVAL("audio/driver/driver", AudioDriverManager::get_driver(0)->get_name()); - if (audio_driver == "") { // Specified in project.godot. + if (audio_driver.is_empty()) { // Specified in project.godot. audio_driver = GLOBAL_GET("audio/driver/driver"); } @@ -1610,9 +1610,9 @@ Error Main::setup2(Thread::ID p_main_tid_override) { ProjectSettings::get_singleton()->set_custom_property_info("input_devices/pen_tablet/driver.windows", PropertyInfo(Variant::STRING, "input_devices/pen_tablet/driver.windows", PROPERTY_HINT_ENUM, "wintab,winink")); } - if (tablet_driver == "") { // specified in project.godot + if (tablet_driver.is_empty()) { // specified in project.godot tablet_driver = GLOBAL_GET("input_devices/pen_tablet/driver"); - if (tablet_driver == "") { + if (tablet_driver.is_empty()) { tablet_driver = DisplayServer::get_singleton()->tablet_get_driver_name(0); } } @@ -1624,7 +1624,7 @@ Error Main::setup2(Thread::ID p_main_tid_override) { } } - if (DisplayServer::get_singleton()->tablet_get_current_driver() == "") { + if (DisplayServer::get_singleton()->tablet_get_current_driver().is_empty()) { DisplayServer::get_singleton()->tablet_set_current_driver(DisplayServer::get_singleton()->tablet_get_driver_name(0)); } @@ -1717,7 +1717,7 @@ Error Main::setup2(Thread::ID p_main_tid_override) { Ref boot_logo; if (boot_logo_image) { - if (boot_logo_path != String()) { + if (!boot_logo_path.is_empty()) { boot_logo.instantiate(); Error load_err = ImageLoader::load_image(boot_logo_path, boot_logo); if (load_err) { @@ -1811,7 +1811,7 @@ Error Main::setup2(Thread::ID p_main_tid_override) { MAIN_PRINT("Main: Load Translations and Remaps"); translation_server->setup(); //register translations, load them, etc. - if (locale != "") { + if (!locale.is_empty()) { translation_server->set_locale(locale); } translation_server->load_translations(); @@ -1833,11 +1833,11 @@ Error Main::setup2(Thread::ID p_main_tid_override) { ProjectSettings::get_singleton()->set_custom_property_info("internationalization/rendering/text_driver", PropertyInfo(Variant::STRING, "internationalization/rendering/text_driver", PROPERTY_HINT_ENUM, text_driver_options)); /* Determine text driver */ - if (text_driver == "") { + if (text_driver.is_empty()) { text_driver = GLOBAL_GET("internationalization/rendering/text_driver"); } - if (text_driver != "") { + if (!text_driver.is_empty()) { /* Load user selected text server. */ for (int i = 0; i < TextServerManager::get_singleton()->get_interface_count(); i++) { if (TextServerManager::get_singleton()->get_interface(i)->get_name() == text_driver) { @@ -1986,7 +1986,7 @@ bool Main::start() { } else if (args[i] == "-p" || args[i] == "--project-manager") { project_manager = true; #endif - } else if (args[i].length() && args[i][0] != '-' && positional_arg == "") { + } else if (args[i].length() && args[i][0] != '-' && positional_arg.is_empty()) { positional_arg = args[i]; if (args[i].ends_with(".scn") || @@ -2045,7 +2045,7 @@ bool Main::start() { } #ifdef TOOLS_ENABLED - if (doc_tool_path != "") { + if (!doc_tool_path.is_empty()) { // Needed to instance editor-only classes for their default values Engine::get_singleton()->set_editor_hint(true); @@ -2124,12 +2124,12 @@ bool Main::start() { } #endif - if (script == "" && game_path == "" && String(GLOBAL_GET("application/run/main_scene")) != "") { + if (script.is_empty() && game_path.is_empty() && String(GLOBAL_GET("application/run/main_scene")) != "") { game_path = GLOBAL_GET("application/run/main_scene"); } #ifdef TOOLS_ENABLED - if (!editor && !project_manager && !cmdline_tool && script == "" && game_path == "") { + if (!editor && !project_manager && !cmdline_tool && script.is_empty() && game_path.is_empty()) { // If we end up here, it means we didn't manage to detect what we want to run. // Let's throw an error gently. The code leading to this is pretty brittle so // this might end up triggered by valid usage, in which case we'll have to @@ -2145,7 +2145,7 @@ bool Main::start() { } String main_loop_type = GLOBAL_DEF("application/run/main_loop_type", "SceneTree"); - if (script != "") { + if (!script.is_empty()) { Ref