diff options
author | Nathan Franke <natfra@pm.me> | 2021-12-09 03:42:46 -0600 |
---|---|---|
committer | Nathan Franke <natfra@pm.me> | 2021-12-09 04:48:38 -0600 |
commit | 49403cbfa0399bb4284ea5c36cc90216a0bda6ff (patch) | |
tree | caa6c7249d35d83b288a180a4f5d7e4fd959704f /modules/gdscript | |
parent | 31ded7e126b9d71ed8dddab9ffc1ce813f1a8ec2 (diff) |
Replace String comparisons with "", String() to is_empty()
Also:
- Adds two stress tests to test_string.h
- Changes to .empty() on std::strings
Diffstat (limited to 'modules/gdscript')
-rw-r--r-- | modules/gdscript/editor/gdscript_highlighter.cpp | 6 | ||||
-rw-r--r-- | modules/gdscript/gdscript.cpp | 22 | ||||
-rw-r--r-- | modules/gdscript/gdscript_cache.cpp | 6 | ||||
-rw-r--r-- | modules/gdscript/gdscript_compiler.cpp | 8 | ||||
-rw-r--r-- | modules/gdscript/gdscript_editor.cpp | 4 | ||||
-rw-r--r-- | modules/gdscript/gdscript_parser.cpp | 4 | ||||
-rw-r--r-- | modules/gdscript/gdscript_vm.cpp | 20 | ||||
-rw-r--r-- | modules/gdscript/tests/gdscript_test_runner.cpp | 2 |
8 files changed, 36 insertions, 36 deletions
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<Script> script = _get_edited_resource(); diff --git a/modules/gdscript/gdscript.cpp b/modules/gdscript/gdscript.cpp index b76c2c0437..4822e411ce 100644 --- a/modules/gdscript/gdscript.cpp +++ b/modules/gdscript/gdscript.cpp @@ -389,7 +389,7 @@ bool GDScript::instance_has(const Object *p_this) const { } bool GDScript::has_source_code() const { - return source != ""; + return !source.is_empty(); } String GDScript::get_source_code() const { @@ -458,7 +458,7 @@ void GDScript::_update_doc() { doc.is_script_doc = true; if (base.is_valid() && base->is_valid()) { - if (base->doc.name != String()) { + if (!base->doc.name.is_empty()) { doc.inherits = base->doc.name; } else { doc.inherits = base->get_instance_base_type(); @@ -472,7 +472,7 @@ void GDScript::_update_doc() { doc.tutorials = doc_tutorials; for (const KeyValue<String, DocData::EnumDoc> &E : doc_enums) { - if (E.value.description != "") { + if (!E.value.description.is_empty()) { doc.enums[E.key] = E.value.description; } } @@ -616,11 +616,11 @@ bool GDScript::_update_exports(bool *r_err, bool p_recursive_call, PlaceHolderSc String basedir = path; - if (basedir == "") { + if (basedir.is_empty()) { basedir = get_path(); } - if (basedir != "") { + if (!basedir.is_empty()) { basedir = basedir.get_base_dir(); } @@ -642,7 +642,7 @@ bool GDScript::_update_exports(bool *r_err, bool p_recursive_call, PlaceHolderSc path = c->extends_path; if (path.is_relative_path()) { String base = get_path(); - if (base == "" || base.is_relative_path()) { + if (base.is_empty() || base.is_relative_path()) { ERR_PRINT(("Could not resolve relative path for parent class: " + path).utf8().get_data()); } else { path = base.get_base_dir().plus_file(path); @@ -656,7 +656,7 @@ bool GDScript::_update_exports(bool *r_err, bool p_recursive_call, PlaceHolderSc } } - if (path != "") { + if (!path.is_empty()) { if (path != get_path()) { Ref<GDScript> bf = ResourceLoader::load(path); @@ -809,11 +809,11 @@ Error GDScript::reload(bool p_keep_state) { String basedir = path; - if (basedir == "") { + if (basedir.is_empty()) { basedir = get_path(); } - if (basedir != "") { + if (!basedir.is_empty()) { basedir = basedir.get_base_dir(); } @@ -1122,7 +1122,7 @@ String GDScript::_get_gdscript_reference_class_name(const GDScript *p_gdscript) String class_name; while (p_gdscript) { - if (class_name == "") { + if (class_name.is_empty()) { class_name = p_gdscript->get_script_class_name(); } else { class_name = p_gdscript->get_script_class_name() + "." + class_name; @@ -1433,7 +1433,7 @@ void GDScriptInstance::get_property_list(List<PropertyInfo> *p_properties) const pinfo.type = Variant::Type(d["type"].operator int()); ERR_CONTINUE(pinfo.type < 0 || pinfo.type >= Variant::VARIANT_MAX); pinfo.name = d["name"]; - ERR_CONTINUE(pinfo.name == ""); + ERR_CONTINUE(pinfo.name.is_empty()); if (d.has("hint")) { pinfo.hint = PropertyHint(d["hint"].operator int()); } diff --git a/modules/gdscript/gdscript_cache.cpp b/modules/gdscript/gdscript_cache.cpp index e99bcddeb7..d0e85147f1 100644 --- a/modules/gdscript/gdscript_cache.cpp +++ b/modules/gdscript/gdscript_cache.cpp @@ -117,7 +117,7 @@ void GDScriptCache::remove_script(const String &p_path) { Ref<GDScriptParserRef> GDScriptCache::get_parser(const String &p_path, GDScriptParserRef::Status p_status, Error &r_error, const String &p_owner) { MutexLock lock(singleton->lock); Ref<GDScriptParserRef> ref; - if (p_owner != String()) { + if (!p_owner.is_empty()) { singleton->dependencies[p_owner].insert(p_path); } if (singleton->parser_map.has(p_path)) { @@ -163,7 +163,7 @@ String GDScriptCache::get_source_code(const String &p_path) { Ref<GDScript> GDScriptCache::get_shallow_script(const String &p_path, const String &p_owner) { MutexLock lock(singleton->lock); - if (p_owner != String()) { + if (!p_owner.is_empty()) { singleton->dependencies[p_owner].insert(p_path); } if (singleton->full_gdscript_cache.has(p_path)) { @@ -186,7 +186,7 @@ Ref<GDScript> GDScriptCache::get_shallow_script(const String &p_path, const Stri Ref<GDScript> GDScriptCache::get_full_script(const String &p_path, Error &r_error, const String &p_owner) { MutexLock lock(singleton->lock); - if (p_owner != String()) { + if (!p_owner.is_empty()) { singleton->dependencies[p_owner].insert(p_path); } diff --git a/modules/gdscript/gdscript_compiler.cpp b/modules/gdscript/gdscript_compiler.cpp index ab0fe5c37d..bba664c328 100644 --- a/modules/gdscript/gdscript_compiler.cpp +++ b/modules/gdscript/gdscript_compiler.cpp @@ -65,7 +65,7 @@ bool GDScriptCompiler::_is_class_member_property(GDScript *owner, const StringNa } void GDScriptCompiler::_set_error(const String &p_error, const GDScriptParser::Node *p_node) { - if (error != "") { + if (!error.is_empty()) { return; } @@ -2020,7 +2020,7 @@ GDScriptFunction *GDScriptCompiler::_parse_function(Error &r_error, GDScript *p_ if (EngineDebugger::is_active()) { String signature; // Path. - if (p_script->get_path() != String()) { + if (!p_script->get_path().is_empty()) { signature += p_script->get_path(); } // Location. @@ -2158,7 +2158,7 @@ Error GDScriptCompiler::_parse_class_level(GDScript *p_script, const GDScriptPar p_script->tool = parser->is_tool(); p_script->name = p_class->identifier ? p_class->identifier->name : ""; - if (p_script->name != "") { + if (!p_script->name.is_empty()) { if (ClassDB::class_exists(p_script->name) && ClassDB::is_class_exposed(p_script->name)) { _set_error("The class '" + p_script->name + "' shadows a native class", p_class); return ERR_ALREADY_EXISTS; @@ -2287,7 +2287,7 @@ Error GDScriptCompiler::_parse_class_level(GDScript *p_script, const GDScriptPar p_script->constants.insert(name, constant->initializer->reduced_value); #ifdef TOOLS_ENABLED p_script->member_lines[name] = constant->start_line; - if (constant->doc_description != String()) { + if (!constant->doc_description.is_empty()) { p_script->doc_constants[name] = constant->doc_description; } #endif diff --git a/modules/gdscript/gdscript_editor.cpp b/modules/gdscript/gdscript_editor.cpp index 71d2699c2e..34fe2364cb 100644 --- a/modules/gdscript/gdscript_editor.cpp +++ b/modules/gdscript/gdscript_editor.cpp @@ -1365,7 +1365,7 @@ static bool _guess_expression_type(GDScriptParser::CompletionContext &p_context, String arg1 = args[0]; if (arg1.begins_with("/root/")) { String which = arg1.get_slice("/", 2); - if (which != "") { + if (!which.is_empty()) { // Try singletons first if (GDScriptLanguage::get_singleton()->get_named_globals_map().has(which)) { r_type = _type_from_variant(GDScriptLanguage::get_singleton()->get_named_globals_map()[which]); @@ -2753,7 +2753,7 @@ void GDScriptLanguage::auto_indent_code(String &p_code, int p_from_line, int p_t } String st = l.substr(tc, l.length()).strip_edges(); - if (st == "" || st.begins_with("#")) { + if (st.is_empty() || st.begins_with("#")) { continue; //ignore! } diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp index fd6bd545c9..98a93a1a53 100644 --- a/modules/gdscript/gdscript_parser.cpp +++ b/modules/gdscript/gdscript_parser.cpp @@ -3100,7 +3100,7 @@ void GDScriptParser::get_class_doc_comment(int p_line, String &p_brief, String & if (!comments.has(p_line)) { return; } - ERR_FAIL_COND(p_brief != "" || p_desc != "" || p_tutorials.size() != 0); + ERR_FAIL_COND(!p_brief.is_empty() || !p_desc.is_empty() || p_tutorials.size() != 0); int line = p_line; bool in_codeblock = false; @@ -3132,7 +3132,7 @@ void GDScriptParser::get_class_doc_comment(int p_line, String &p_brief, String & String striped_line = doc_line.strip_edges(); // Set the read mode. - if (striped_line.begins_with("@desc:") && p_desc == "") { + if (striped_line.begins_with("@desc:") && p_desc.is_empty()) { mode = DESC; striped_line = striped_line.trim_prefix("@desc:"); in_codeblock = _in_codeblock(doc_line, in_codeblock); diff --git a/modules/gdscript/gdscript_vm.cpp b/modules/gdscript/gdscript_vm.cpp index 6dd8c3e0dd..be9e5df2b0 100644 --- a/modules/gdscript/gdscript_vm.cpp +++ b/modules/gdscript/gdscript_vm.cpp @@ -755,7 +755,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a #ifdef DEBUG_ENABLED if (!valid) { String v = index->operator String(); - if (v != "") { + if (!v.is_empty()) { v = "'" + v + "'"; } else { v = "of type '" + _get_var_type(index) + "'"; @@ -785,7 +785,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a #ifdef DEBUG_ENABLED if (!valid) { String v = index->operator String(); - if (v != "") { + if (!v.is_empty()) { v = "'" + v + "'"; } else { v = "of type '" + _get_var_type(index) + "'"; @@ -817,7 +817,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a #ifdef DEBUG_ENABLED if (oob) { String v = index->operator String(); - if (v != "") { + if (!v.is_empty()) { v = "'" + v + "'"; } else { v = "of type '" + _get_var_type(index) + "'"; @@ -848,7 +848,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a #ifdef DEBUG_ENABLED if (!valid) { String v = index->operator String(); - if (v != "") { + if (!v.is_empty()) { v = "'" + v + "'"; } else { v = "of type '" + _get_var_type(index) + "'"; @@ -884,7 +884,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a #ifdef DEBUG_ENABLED if (!valid) { String v = key->operator String(); - if (v != "") { + if (!v.is_empty()) { v = "'" + v + "'"; } else { v = "of type '" + _get_var_type(key) + "'"; @@ -917,7 +917,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a #ifdef DEBUG_ENABLED if (oob) { String v = index->operator String(); - if (v != "") { + if (!v.is_empty()) { v = "'" + v + "'"; } else { v = "of type '" + _get_var_type(index) + "'"; @@ -3295,20 +3295,20 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a //error // function, file, line, error, explanation String err_file; - if (p_instance && ObjectDB::get_instance(p_instance->owner_id) != nullptr && p_instance->script->is_valid() && p_instance->script->path != "") { + if (p_instance && ObjectDB::get_instance(p_instance->owner_id) != nullptr && p_instance->script->is_valid() && !p_instance->script->path.is_empty()) { err_file = p_instance->script->path; } else if (script) { err_file = script->path; } - if (err_file == "") { + if (err_file.is_empty()) { err_file = "<built-in>"; } String err_func = name; - if (p_instance && ObjectDB::get_instance(p_instance->owner_id) != nullptr && p_instance->script->is_valid() && p_instance->script->name != "") { + if (p_instance && ObjectDB::get_instance(p_instance->owner_id) != nullptr && p_instance->script->is_valid() && !p_instance->script->name.is_empty()) { err_func = p_instance->script->name + "." + err_func; } int err_line = line; - if (err_text == "") { + if (err_text.is_empty()) { err_text = "Internal script error! Opcode: " + itos(last_opcode) + " (please report)."; } diff --git a/modules/gdscript/tests/gdscript_test_runner.cpp b/modules/gdscript/tests/gdscript_test_runner.cpp index d2e71efee7..21883b3c6e 100644 --- a/modules/gdscript/tests/gdscript_test_runner.cpp +++ b/modules/gdscript/tests/gdscript_test_runner.cpp @@ -267,7 +267,7 @@ bool GDScriptTestRunner::generate_class_index() { String base_type; String class_name = GDScriptLanguage::get_singleton()->get_global_class_name(test.get_source_file(), &base_type); - if (class_name == String()) { + if (class_name.is_empty()) { continue; } ERR_FAIL_COND_V_MSG(ScriptServer::is_global_class(class_name), false, |