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 /editor/import | |
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 'editor/import')
-rw-r--r-- | editor/import/collada.cpp | 26 | ||||
-rw-r--r-- | editor/import/dynamicfont_import_settings.cpp | 6 | ||||
-rw-r--r-- | editor/import/editor_import_collada.cpp | 50 | ||||
-rw-r--r-- | editor/import/resource_importer_csv_translation.cpp | 2 | ||||
-rw-r--r-- | editor/import/resource_importer_obj.cpp | 8 | ||||
-rw-r--r-- | editor/import/resource_importer_scene.cpp | 14 | ||||
-rw-r--r-- | editor/import/scene_import_settings.cpp | 6 |
7 files changed, 56 insertions, 56 deletions
diff --git a/editor/import/collada.cpp b/editor/import/collada.cpp index c34379f1ec..c1f577f176 100644 --- a/editor/import/collada.cpp +++ b/editor/import/collada.cpp @@ -1362,7 +1362,7 @@ Collada::Node *Collada::_parse_visual_instance_geometry(XMLParser &parser) { } else if (parser.get_node_name() == "skeleton") { parser.read(); String uri = _uri_to_id(parser.get_node_data()); - if (uri != "") { + if (!uri.is_empty()) { geom->skeletons.push_back(uri); } } @@ -1464,7 +1464,7 @@ Collada::Node *Collada::_parse_visual_scene_node(XMLParser &parser) { bool found_name = false; - if (id == "") { + if (id.is_empty()) { id = "%NODEID%" + itos(Math::rand()); } else { @@ -1479,7 +1479,7 @@ Collada::Node *Collada::_parse_visual_scene_node(XMLParser &parser) { Node *node = nullptr; name = parser.has_attribute("name") ? parser.get_attribute_value_safe("name") : parser.get_attribute_value_safe("id"); - if (name == "") { + if (name.is_empty()) { name = id; } else { found_name = true; @@ -1499,7 +1499,7 @@ Collada::Node *Collada::_parse_visual_scene_node(XMLParser &parser) { joint->sid = parser.get_attribute_value_safe("name"); } - if (joint->sid != "") { + if (!joint->sid.is_empty()) { state.sid_to_node_map[joint->sid] = id; } @@ -1696,16 +1696,16 @@ void Collada::_parse_animation(XMLParser &parser) { source_param_types[current_source] = Vector<String>(); } else if (name == "float_array") { - if (current_source != "") { + if (!current_source.is_empty()) { float_sources[current_source] = _read_float_array(parser); } } else if (name == "Name_array") { - if (current_source != "") { + if (!current_source.is_empty()) { string_sources[current_source] = _read_string_array(parser); } } else if (name == "accessor") { - if (current_source != "" && parser.has_attribute("stride")) { + if (!current_source.is_empty() && parser.has_attribute("stride")) { source_strides[current_source] = parser.get_attribute_value("stride").to_int(); } } else if (name == "sampler") { @@ -1725,7 +1725,7 @@ void Collada::_parse_animation(XMLParser &parser) { } } else if (name == "input") { - if (current_sampler != "") { + if (!current_sampler.is_empty()) { samplers[current_sampler][parser.get_attribute_value("semantic")] = parser.get_attribute_value("source"); } @@ -1838,7 +1838,7 @@ void Collada::_parse_animation(XMLParser &parser) { track.component = track.param.get_slice(".", 1).to_upper(); } track.param = track.param.get_slice(".", 0); - if (names.size() > 1 && track.component == "") { + if (names.size() > 1 && track.component.is_empty()) { //this is a guess because the collada spec is ambiguous here... //i suppose if you have many names (outputs) you can't use a component and i should abide to that. track.component = name; @@ -1855,7 +1855,7 @@ void Collada::_parse_animation(XMLParser &parser) { state.referenced_tracks[target].push_back(state.animation_tracks.size() - 1); - if (id != "") { + if (!id.is_empty()) { if (!state.by_id_tracks.has(id)) { state.by_id_tracks[id] = Vector<int>(); } @@ -1953,10 +1953,10 @@ void Collada::_parse_library(XMLParser &parser) { while (parser.read() == OK) { if (parser.get_node_type() == XMLParser::NODE_ELEMENT) { if (parser.get_node_name() == "mesh") { - state.mesh_name_map[id] = (name2 != "") ? name2 : id; + state.mesh_name_map[id] = (!name2.is_empty()) ? name2 : id; _parse_mesh_geometry(parser, id, name2); } else if (parser.get_node_name() == "spline") { - state.mesh_name_map[id] = (name2 != "") ? name2 : id; + state.mesh_name_map[id] = (!name2.is_empty()) ? name2 : id; _parse_curve_geometry(parser, id, name2); } else if (!parser.is_empty()) { parser.skip_section(); @@ -2286,7 +2286,7 @@ void Collada::_find_morph_nodes(VisualScene *p_vscene, Node *p_node) { if (nj->controller) { String base = nj->source; - while (base != "" && !state.mesh_data_map.has(base)) { + while (!base.is_empty() && !state.mesh_data_map.has(base)) { if (state.skin_controller_data_map.has(base)) { SkinControllerData &sk = state.skin_controller_data_map[base]; base = sk.base; diff --git a/editor/import/dynamicfont_import_settings.cpp b/editor/import/dynamicfont_import_settings.cpp index 83c0f56d87..b63c2bf350 100644 --- a/editor/import/dynamicfont_import_settings.cpp +++ b/editor/import/dynamicfont_import_settings.cpp @@ -1597,7 +1597,7 @@ DynamicFontImportSettings::DynamicFontImportSettings() { menu_langs = memnew(PopupMenu); menu_langs->set_name("Language"); - for (int i = 0; langs[i].name != String(); i++) { + for (int i = 0; !langs[i].name.is_empty(); i++) { if (langs[i].name == "-") { menu_langs->add_separator(); } else { @@ -1609,7 +1609,7 @@ DynamicFontImportSettings::DynamicFontImportSettings() { menu_scripts = memnew(PopupMenu); menu_scripts->set_name("Script"); - for (int i = 0; scripts[i].name != String(); i++) { + for (int i = 0; !scripts[i].name.is_empty(); i++) { if (scripts[i].name == "-") { menu_scripts->add_separator(); } else { @@ -1826,7 +1826,7 @@ DynamicFontImportSettings::DynamicFontImportSettings() { glyph_tree->connect("item_selected", callable_mp(this, &DynamicFontImportSettings::_range_selected)); glyph_tree->set_v_size_flags(Control::SIZE_EXPAND_FILL); glyph_root = glyph_tree->create_item(); - for (int i = 0; unicode_ranges[i].name != String(); i++) { + for (int i = 0; !unicode_ranges[i].name.is_empty(); i++) { _add_glyph_range_item(unicode_ranges[i].start, unicode_ranges[i].end, unicode_ranges[i].name); } diff --git a/editor/import/editor_import_collada.cpp b/editor/import/editor_import_collada.cpp index 076c0cc62b..91f8e5b910 100644 --- a/editor/import/editor_import_collada.cpp +++ b/editor/import/editor_import_collada.cpp @@ -303,7 +303,7 @@ Error ColladaImport::_create_scene(Collada::Node *p_node, Node3D *p_parent) { } break; } - if (p_node->name != "") { + if (!p_node->name.is_empty()) { node->set_name(p_node->name); } NodeMap nm; @@ -317,7 +317,7 @@ Error ColladaImport::_create_scene(Collada::Node *p_node, Node3D *p_parent) { p_parent->add_child(node, true); node->set_owner(scene); - if (p_node->empty_draw_type != "") { + if (!p_node->empty_draw_type.is_empty()) { node->set_meta("empty_draw_type", Variant(p_node->empty_draw_type)); } @@ -340,9 +340,9 @@ Error ColladaImport::_create_material(const String &p_target) { Ref<StandardMaterial3D> material = memnew(StandardMaterial3D); String base_name; - if (src_mat.name != "") { + if (!src_mat.name.is_empty()) { base_name = src_mat.name; - } else if (effect.name != "") { + } else if (!effect.name.is_empty()) { base_name = effect.name; } else { base_name = "Material"; @@ -360,9 +360,9 @@ Error ColladaImport::_create_material(const String &p_target) { // DIFFUSE - if (effect.diffuse.texture != "") { + if (!effect.diffuse.texture.is_empty()) { String texfile = effect.get_texture_path(effect.diffuse.texture, collada); - if (texfile != "") { + if (!texfile.is_empty()) { if (texfile.begins_with("/")) { texfile = texfile.replace_first("/", "res://"); } @@ -381,9 +381,9 @@ Error ColladaImport::_create_material(const String &p_target) { // SPECULAR - if (effect.specular.texture != "") { + if (!effect.specular.texture.is_empty()) { String texfile = effect.get_texture_path(effect.specular.texture, collada); - if (texfile != "") { + if (!texfile.is_empty()) { if (texfile.begins_with("/")) { texfile = texfile.replace_first("/", "res://"); } @@ -406,9 +406,9 @@ Error ColladaImport::_create_material(const String &p_target) { // EMISSION - if (effect.emission.texture != "") { + if (!effect.emission.texture.is_empty()) { String texfile = effect.get_texture_path(effect.emission.texture, collada); - if (texfile != "") { + if (!texfile.is_empty()) { if (texfile.begins_with("/")) { texfile = texfile.replace_first("/", "res://"); } @@ -433,9 +433,9 @@ Error ColladaImport::_create_material(const String &p_target) { // NORMAL - if (effect.bump.texture != "") { + if (!effect.bump.texture.is_empty()) { String texfile = effect.get_texture_path(effect.bump.texture, collada); - if (texfile != "") { + if (!texfile.is_empty()) { if (texfile.begins_with("/")) { texfile = texfile.replace_first("/", "res://"); } @@ -525,7 +525,7 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref<ImporterMesh> &p normal_ofs = vertex_ofs; } - if (normal_source_id != "") { + if (!normal_source_id.is_empty()) { ERR_FAIL_COND_V(!meshdata.sources.has(normal_source_id), ERR_INVALID_DATA); normal_src = &meshdata.sources[normal_source_id]; } @@ -545,7 +545,7 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref<ImporterMesh> &p binormal_ofs = vertex_ofs; } - if (binormal_source_id != "") { + if (!binormal_source_id.is_empty()) { ERR_FAIL_COND_V(!meshdata.sources.has(binormal_source_id), ERR_INVALID_DATA); binormal_src = &meshdata.sources[binormal_source_id]; } @@ -565,7 +565,7 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref<ImporterMesh> &p tangent_ofs = vertex_ofs; } - if (tangent_source_id != "") { + if (!tangent_source_id.is_empty()) { ERR_FAIL_COND_V(!meshdata.sources.has(tangent_source_id), ERR_INVALID_DATA); tangent_src = &meshdata.sources[tangent_source_id]; } @@ -585,7 +585,7 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref<ImporterMesh> &p uv_ofs = vertex_ofs; } - if (uv_source_id != "") { + if (!uv_source_id.is_empty()) { ERR_FAIL_COND_V(!meshdata.sources.has(uv_source_id), ERR_INVALID_DATA); uv_src = &meshdata.sources[uv_source_id]; } @@ -605,7 +605,7 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref<ImporterMesh> &p uv2_ofs = vertex_ofs; } - if (uv2_source_id != "") { + if (!uv2_source_id.is_empty()) { ERR_FAIL_COND_V(!meshdata.sources.has(uv2_source_id), ERR_INVALID_DATA); uv2_src = &meshdata.sources[uv2_source_id]; } @@ -625,7 +625,7 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref<ImporterMesh> &p color_ofs = vertex_ofs; } - if (color_source_id != "") { + if (!color_source_id.is_empty()) { ERR_FAIL_COND_V(!meshdata.sources.has(color_source_id), ERR_INVALID_DATA); color_src = &meshdata.sources[color_source_id]; } @@ -914,7 +914,7 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref<ImporterMesh> &p material = material_cache[target]; } - } else if (p.material != "") { + } else if (!p.material.is_empty()) { WARN_PRINT("Collada: Unreferenced material in geometry instance: " + p.material); } } @@ -1198,7 +1198,7 @@ Error ColladaImport::_create_resources(Collada::Node *p_node, bool p_use_compres } } - ERR_FAIL_COND_V_MSG(ngsource != "", ERR_INVALID_DATA, "Controller instance source '" + ngsource + "' is neither skin or morph!"); + ERR_FAIL_COND_V_MSG(!ngsource.is_empty(), ERR_INVALID_DATA, "Controller instance source '" + ngsource + "' is neither skin or morph!"); } else { meshid = ng2->source; @@ -1215,13 +1215,13 @@ Error ColladaImport::_create_resources(Collada::Node *p_node, bool p_use_compres mesh = Ref<ImporterMesh>(memnew(ImporterMesh)); const Collada::MeshData &meshdata = collada.state.mesh_data_map[meshid]; String name = meshdata.name; - if (name == "") { + if (name.is_empty()) { name = "Mesh"; } int counter = 2; while (mesh_unique_names.has(name)) { name = meshdata.name; - if (name == "") { + if (name.is_empty()) { name = "Mesh"; } name += itos(counter++); @@ -1261,7 +1261,7 @@ Error ColladaImport::_create_resources(Collada::Node *p_node, bool p_use_compres } mi->set_surface_material(i, material); - } else if (matname != "") { + } else if (!matname.is_empty()) { WARN_PRINT("Collada: Unreferenced material in geometry instance: " + matname); } } @@ -1343,7 +1343,7 @@ void ColladaImport::_fix_param_animation_tracks() { // test source(s) String source = ng->source; - while (source != "") { + while (!source.is_empty()) { if (collada.state.skin_controller_data_map.has(source)) { const Collada::SkinControllerData &skin = collada.state.skin_controller_data_map[source]; @@ -1796,7 +1796,7 @@ Node *EditorSceneFormatImporterCollada::import_scene(const String &p_path, uint3 AnimationPlayer *ap = memnew(AnimationPlayer); for (int i = 0; i < state.animations.size(); i++) { String name; - if (state.animations[i]->get_name() == "") { + if (state.animations[i]->get_name().is_empty()) { name = "default"; } else { name = state.animations[i]->get_name(); diff --git a/editor/import/resource_importer_csv_translation.cpp b/editor/import/resource_importer_csv_translation.cpp index 7948d9e577..7a226802f2 100644 --- a/editor/import/resource_importer_csv_translation.cpp +++ b/editor/import/resource_importer_csv_translation.cpp @@ -113,7 +113,7 @@ Error ResourceImporterCSVTranslation::import(const String &p_source_file, const while (line.size() == locales.size() + 1) { String key = line[0]; - if (key != "") { + if (!key.is_empty()) { for (int i = 1; i < line.size(); i++) { translations.write[i - 1]->add_message(key, line[i].c_unescape()); } diff --git a/editor/import/resource_importer_obj.cpp b/editor/import/resource_importer_obj.cpp index bb68de99b1..9e3cdbdeff 100644 --- a/editor/import/resource_importer_obj.cpp +++ b/editor/import/resource_importer_obj.cpp @@ -235,7 +235,7 @@ static Error _parse_obj(const String &p_path, List<Ref<Mesh>> &r_meshes, bool p_ while (l.length() && l[l.length() - 1] == '\\') { String add = f->get_line().strip_edges(); l += add; - if (add == String()) { + if (add.is_empty()) { break; } } @@ -301,7 +301,7 @@ static Error _parse_obj(const String &p_path, List<Ref<Mesh>> &r_meshes, bool p_ surf_tool->set_normal(normals[norm]); } - if (face[idx].size() >= 2 && face[idx][1] != String()) { + if (face[idx].size() >= 2 && !face[idx][1].is_empty()) { int uv = face[idx][1].to_int() - 1; if (uv < 0) { uv += uvs.size() + 1; @@ -363,9 +363,9 @@ static Error _parse_obj(const String &p_path, List<Ref<Mesh>> &r_meshes, bool p_ mesh = surf_tool->commit(mesh, mesh_flags); - if (current_material != String()) { + if (!current_material.is_empty()) { mesh->surface_set_name(mesh->get_surface_count() - 1, current_material.get_basename()); - } else if (current_group != String()) { + } else if (!current_group.is_empty()) { mesh->surface_set_name(mesh->get_surface_count() - 1, current_group); } diff --git a/editor/import/resource_importer_scene.cpp b/editor/import/resource_importer_scene.cpp index a25b694a60..330c7125fe 100644 --- a/editor/import/resource_importer_scene.cpp +++ b/editor/import/resource_importer_scene.cpp @@ -481,7 +481,7 @@ Node *ResourceImporterScene::_pre_fix_node(Node *p_node, Node *p_root, Map<Ref<I fixed_name = _fixstr(name, "convcolonly"); } - ERR_FAIL_COND_V(fixed_name == String(), nullptr); + ERR_FAIL_COND_V(fixed_name.is_empty(), nullptr); if (shapes.size()) { StaticBody3D *col = memnew(StaticBody3D); @@ -577,7 +577,7 @@ Node *ResourceImporterScene::_pre_fix_node(Node *p_node, Node *p_root, Map<Ref<I fixed_name = _fixstr(name, "convcol"); } - if (fixed_name != String()) { + if (!fixed_name.is_empty()) { if (mi->get_parent() && !mi->get_parent()->has_node(fixed_name)) { mi->set_name(fixed_name); } @@ -710,7 +710,7 @@ Node *ResourceImporterScene::_post_fix_node(Node *p_node, Node *p_root, Map<Ref< mat_id = mat->get_name(); } - if (mat_id != String() && p_material_data.has(mat_id)) { + if (!mat_id.is_empty() && p_material_data.has(mat_id)) { Dictionary matdata = p_material_data[mat_id]; for (int j = 0; j < post_importer_plugins.size(); j++) { @@ -1433,7 +1433,7 @@ void ResourceImporterScene::get_import_options(const String &p_path, List<Import String script_ext_hint; for (const String &E : script_extentions) { - if (script_ext_hint != "") { + if (!script_ext_hint.is_empty()) { script_ext_hint += ","; } script_ext_hint += "*." + E; @@ -1559,7 +1559,7 @@ void ResourceImporterScene::_generate_meshes(Node *p_node, const Dictionary &p_m mesh_id = src_mesh_node->get_mesh()->get_name(); } - if (mesh_id != String() && p_mesh_data.has(mesh_id)) { + if (!mesh_id.is_empty() && p_mesh_data.has(mesh_id)) { Dictionary mesh_settings = p_mesh_data[mesh_id]; if (mesh_settings.has("generate/shadow_meshes")) { @@ -1649,7 +1649,7 @@ void ResourceImporterScene::_generate_meshes(Node *p_node, const Dictionary &p_m } } - if (save_to_file != String()) { + if (!save_to_file.is_empty()) { Ref<Mesh> existing = Ref<Resource>(ResourceCache::get(save_to_file)); if (existing.is_valid()) { //if somehow an existing one is useful, create @@ -2051,7 +2051,7 @@ Error ResourceImporterScene::import(const String &p_source_file, const String &p String post_import_script_path = p_options["import_script/path"]; Ref<EditorScenePostImport> post_import_script; - if (post_import_script_path != "") { + if (!post_import_script_path.is_empty()) { Ref<Script> scr = ResourceLoader::load(post_import_script_path); if (!scr.is_valid()) { EditorNode::add_io_error(TTR("Couldn't load post-import script:") + " " + post_import_script_path); diff --git a/editor/import/scene_import_settings.cpp b/editor/import/scene_import_settings.cpp index 5690d49a55..a376596f9b 100644 --- a/editor/import/scene_import_settings.cpp +++ b/editor/import/scene_import_settings.cpp @@ -92,7 +92,7 @@ void SceneImportSettings::_fill_material(Tree *p_tree, const Ref<Material> &p_ma if (p_material->has_meta("import_id")) { import_id = p_material->get_meta("import_id"); has_import_id = true; - } else if (p_material->get_name() != "") { + } else if (!p_material->get_name().is_empty()) { import_id = p_material->get_name(); has_import_id = true; } else { @@ -148,7 +148,7 @@ void SceneImportSettings::_fill_mesh(Tree *p_tree, const Ref<Mesh> &p_mesh, Tree if (p_mesh->has_meta("import_id")) { import_id = p_mesh->get_meta("import_id"); has_import_id = true; - } else if (p_mesh->get_name() != String()) { + } else if (!p_mesh->get_name().is_empty()) { import_id = p_mesh->get_name(); has_import_id = true; } else { @@ -414,7 +414,7 @@ void SceneImportSettings::_update_camera() { float rot_y = cam_rot_y; float zoom = cam_zoom; - if (selected_type == "Node" || selected_type == "") { + if (selected_type == "Node" || selected_type.is_empty()) { camera_aabb = contents_aabb; } else { if (mesh_preview->get_mesh().is_valid()) { |