Skip to content

Commit

Permalink
Replace find with contains/has where applicable
Browse files Browse the repository at this point in the history
* Replaces `find(...) != -1` with `contains` for `String`
* Replaces `find(...) == -1` with `!contains` for `String`
* Replaces `find(...) != -1` with `has` for containers
* Replaces `find(...) == -1` with `!has` for containers
  • Loading branch information
AThousandShips committed May 8, 2024
1 parent 281fe39 commit a0dbdcc
Show file tree
Hide file tree
Showing 55 changed files with 219 additions and 219 deletions.
2 changes: 1 addition & 1 deletion core/debugger/engine_debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ void EngineDebugger::initialize(const String &p_uri, bool p_skip_breakpoints, co
script_debugger = memnew(ScriptDebugger);
// Tell the OS that we want to handle termination signals.
OS::get_singleton()->initialize_debugging();
} else if (p_uri.find("://") >= 0) {
} else if (p_uri.contains("://")) {
const String proto = p_uri.substr(0, p_uri.find("://") + 3);
if (!protocols.has(proto)) {
return;
Expand Down
2 changes: 1 addition & 1 deletion core/extension/extension_api_dump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1201,7 +1201,7 @@ Dictionary GDExtensionAPIDump::generate_extension_api(bool p_include_docs) {
if (F.name.begins_with("_")) {
continue; //hidden property
}
if (F.name.find("/") >= 0) {
if (F.name.contains("/")) {
// Ignore properties with '/' (slash) in the name. These are only meant for use in the inspector.
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion core/io/ip_address.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ IPAddress::IPAddress(const String &p_string) {
// Wildcard (not a valid IP)
wildcard = true;

} else if (p_string.find(":") >= 0) {
} else if (p_string.contains(":")) {
// IPv6
_parse_ipv6(p_string);
valid = true;
Expand Down
2 changes: 1 addition & 1 deletion core/string/ustring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3964,7 +3964,7 @@ String String::format(const Variant &values, const String &placeholder) const {
Variant v_val = values_arr[i];
String val = v_val;

if (placeholder.find("_") > -1) {
if (placeholder.contains("_")) {
new_string = new_string.replace(placeholder.replace("_", i_as_str), val);
} else {
new_string = new_string.replace_first(placeholder, val);
Expand Down
2 changes: 1 addition & 1 deletion drivers/alsa/audio_driver_alsa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Error AudioDriverALSA::init_output_device() {
// If there is a specified output device check that it is really present
if (output_device_name != "Default") {
PackedStringArray list = get_output_device_list();
if (list.find(output_device_name) == -1) {
if (!list.has(output_device_name)) {
output_device_name = "Default";
new_output_device = "Default";
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/egl/egl_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ Error EGLManager::initialize() {
ERR_FAIL_COND_V(eglGetError() != EGL_SUCCESS, ERR_BUG);

const char *platform = _get_platform_extension_name();
if (extensions_string.split(" ").find(platform) < 0) {
if (!extensions_string.split(" ").has(platform)) {
ERR_FAIL_V_MSG(ERR_UNAVAILABLE, vformat("EGL platform extension \"%s\" not found.", platform));
}

Expand Down
4 changes: 2 additions & 2 deletions drivers/pulseaudio/audio_driver_pulseaudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ Error AudioDriverPulseAudio::init_output_device() {
// If there is a specified output device, check that it is really present
if (output_device_name != "Default") {
PackedStringArray list = get_output_device_list();
if (list.find(output_device_name) == -1) {
if (!list.has(output_device_name)) {
output_device_name = "Default";
new_output_device = "Default";
}
Expand Down Expand Up @@ -695,7 +695,7 @@ Error AudioDriverPulseAudio::init_input_device() {
// If there is a specified input device, check that it is really present
if (input_device_name != "Default") {
PackedStringArray list = get_input_device_list();
if (list.find(input_device_name) == -1) {
if (!list.has(input_device_name)) {
input_device_name = "Default";
new_input_device = "Default";
}
Expand Down
2 changes: 1 addition & 1 deletion editor/create_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ float CreateDialog::_score_type(const String &p_type, const String &p_search) co
score *= _is_type_preferred(p_type) ? 1.0f : 0.9f;

// Add score for being a favorite type.
score *= (favorite_list.find(p_type) > -1) ? 1.0f : 0.8f;
score *= favorite_list.has(p_type) ? 1.0f : 0.8f;

// Look through at most 5 recent items
bool in_recent = false;
Expand Down
2 changes: 1 addition & 1 deletion editor/debugger/debug_adapter/debug_adapter_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ Dictionary DebugAdapterParser::req_setBreakpoints(const Dictionary &p_params) co
}

// If path contains \, it's a Windows path, so we need to convert it to /, and make the drive letter uppercase
if (source.path.find("\\") != -1) {
if (source.path.contains("\\")) {
source.path = source.path.replace("\\", "/");
source.path = source.path.substr(0, 1).to_upper() + source.path.substr(1);
}
Expand Down
2 changes: 1 addition & 1 deletion editor/debugger/editor_debugger_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ void EditorDebuggerNode::set_keep_open(bool p_keep_open) {
}

Error EditorDebuggerNode::start(const String &p_uri) {
ERR_FAIL_COND_V(p_uri.find("://") < 0, ERR_INVALID_PARAMETER);
ERR_FAIL_COND_V(!p_uri.contains("://"), ERR_INVALID_PARAMETER);
if (keep_open && current_uri == p_uri && server.is_valid()) {
return OK;
}
Expand Down
2 changes: 1 addition & 1 deletion editor/debugger/editor_file_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void EditorFileServer::_scan_files_changed(EditorFileSystemDirectory *efd, const
_add_file(remapped_path, mt, files_to_send, cached_files);
} else if (remap.begins_with("path.")) {
String feature = remap.get_slice(".", 1);
if (p_tags.find(feature) != -1) {
if (p_tags.has(feature)) {
String remapped_path = cf->get_value("remap", remap);
uint64_t mt = FileAccess::get_modified_time(remapped_path);
_add_file(remapped_path, mt, files_to_send, cached_files);
Expand Down
4 changes: 2 additions & 2 deletions editor/dependency_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -642,11 +642,11 @@ void DependencyRemoveDialog::ok_pressed() {

for (int i = 0; i < previous_favorites.size(); ++i) {
if (previous_favorites[i].ends_with("/")) {
if (dirs_to_delete.find(previous_favorites[i]) < 0) {
if (!dirs_to_delete.has(previous_favorites[i])) {
new_favorites.push_back(previous_favorites[i]);
}
} else {
if (files_to_delete.find(previous_favorites[i]) < 0) {
if (!files_to_delete.has(previous_favorites[i])) {
new_favorites.push_back(previous_favorites[i]);
}
}
Expand Down
2 changes: 1 addition & 1 deletion editor/doc_tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1638,7 +1638,7 @@ Error DocTools::save_classes(const String &p_default_path, const HashMap<String,
String schema_path;
if (p_use_relative_schema) {
// Modules are nested deep, so change the path to reference the same schema everywhere.
schema_path = save_path.find("modules/") != -1 ? "../../../doc/class.xsd" : "../class.xsd";
schema_path = save_path.contains("modules/") ? "../../../doc/class.xsd" : "../class.xsd";
} else {
schema_path = "https://raw.githubusercontent.com/godotengine/godot/master/doc/class.xsd";
}
Expand Down
4 changes: 2 additions & 2 deletions editor/editor_file_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ void EditorFileSystem::_scan_filesystem() {

FileCache fc;
fc.type = split[1];
if (fc.type.find("/") != -1) {
if (fc.type.contains("/")) {
fc.type = fc.type.get_slice("/", 0);
fc.resource_script_class = fc.type.get_slice("/", 1);
}
Expand Down Expand Up @@ -2707,7 +2707,7 @@ void EditorFileSystem::_update_extensions() {
}

void EditorFileSystem::add_import_format_support_query(Ref<EditorFileSystemImportFormatSupportQuery> p_query) {
ERR_FAIL_COND(import_support_queries.find(p_query) != -1);
ERR_FAIL_COND(import_support_queries.has(p_query));
import_support_queries.push_back(p_query);
}
void EditorFileSystem::remove_import_format_support_query(Ref<EditorFileSystemImportFormatSupportQuery> p_query) {
Expand Down
2 changes: 1 addition & 1 deletion editor/editor_help_search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ String EditorHelpSearch::Runner::_match_keywords_in_all_terms(const String &p_ke

bool EditorHelpSearch::Runner::_match_string(const String &p_term, const String &p_string) const {
if (search_flags & SEARCH_CASE_SENSITIVE) {
return p_string.find(p_term) > -1;
return p_string.contains(p_term);
} else {
return p_string.findn(p_term) > -1;
}
Expand Down
2 changes: 1 addition & 1 deletion editor/editor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2391,7 +2391,7 @@ void EditorNode::_edit_current(bool p_skip_foreign, bool p_skip_inspector_update
Ref<Resource> res = Object::cast_to<Resource>(current_obj);
if (p_skip_foreign && res.is_valid()) {
const int current_tab = scene_tabs->get_current_tab();
if (res->get_path().find("::") > -1 && res->get_path().get_slice("::", 0) != editor_data.get_scene_path(current_tab)) {
if (res->get_path().contains("::") && res->get_path().get_slice("::", 0) != editor_data.get_scene_path(current_tab)) {
// Trying to edit resource that belongs to another scene; abort.
current_obj = nullptr;
}
Expand Down
2 changes: 1 addition & 1 deletion editor/editor_property_name_processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ bool EditorPropertyNameProcessor::is_localization_available() {
return false;
}
const Vector<String> forbidden = String("en").split(",");
return forbidden.find(EDITOR_GET("interface/editor/editor_language")) == -1;
return !forbidden.has(EDITOR_GET("interface/editor/editor_language"));
}

String EditorPropertyNameProcessor::_capitalize_name(const String &p_name) const {
Expand Down
2 changes: 1 addition & 1 deletion editor/editor_quick_open.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ float EditorQuickOpen::_score_search_result(const PackedStringArray &p_search_to
}

// Prioritize matches at the front of the path token.
if (min_match_idx == 0 || p_path.find("/" + s) != -1) {
if (min_match_idx == 0 || p_path.contains("/" + s)) {
token_score += 1.0f;
}

Expand Down
4 changes: 2 additions & 2 deletions editor/editor_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -969,7 +969,7 @@ bool EditorSettings::_save_text_editor_theme(const String &p_file) {
keys.sort();

for (const String &key : keys) {
if (key.begins_with("text_editor/theme/highlighting/") && key.find("color") >= 0) {
if (key.begins_with("text_editor/theme/highlighting/") && key.contains("color")) {
cf->set_value(theme_section, key.replace("text_editor/theme/highlighting/", ""), ((Color)props[key].variant).to_html());
}
}
Expand Down Expand Up @@ -1448,7 +1448,7 @@ void EditorSettings::load_text_editor_theme() {
// don't load if it's not already there!
if (has_setting("text_editor/theme/highlighting/" + key)) {
// make sure it is actually a color
if (val.is_valid_html_color() && key.find("color") >= 0) {
if (val.is_valid_html_color() && key.contains("color")) {
props["text_editor/theme/highlighting/" + key].variant = Color::html(val); // change manually to prevent "Settings changed" console spam
}
}
Expand Down
6 changes: 3 additions & 3 deletions editor/filesystem_dock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ bool FileSystemDock::_create_tree(TreeItem *p_parent, EditorFileSystemDirectory
if (p_unfold_path && current_path.begins_with(lpath) && current_path != lpath) {
subdirectory_item->set_collapsed(false);
} else {
subdirectory_item->set_collapsed(uncollapsed_paths.find(lpath) < 0);
subdirectory_item->set_collapsed(!uncollapsed_paths.has(lpath));
}
if (!searched_tokens.is_empty() && _matches_all_search_tokens(dname)) {
parent_should_expand = true;
Expand Down Expand Up @@ -407,7 +407,7 @@ void FileSystemDock::_update_tree(const Vector<String> &p_uncollapsed_paths, boo
favorites_item->set_icon(0, get_editor_theme_icon(SNAME("Favorites")));
favorites_item->set_text(0, TTR("Favorites:"));
favorites_item->set_metadata(0, "Favorites");
favorites_item->set_collapsed(p_uncollapsed_paths.find("Favorites") < 0);
favorites_item->set_collapsed(!p_uncollapsed_paths.has("Favorites"));

Vector<String> favorite_paths = EditorSettings::get_singleton()->get_favorites();

Expand Down Expand Up @@ -2300,7 +2300,7 @@ void FileSystemDock::_file_option(int p_option, const Vector<String> &p_selected
TreeItem *selected = tree->get_root();
selected = tree->get_next_selected(selected);
while (selected) {
if (p_selected.find(selected->get_metadata(0)) >= 0) {
if (p_selected.has(selected->get_metadata(0))) {
selected->set_collapsed(false);
}
selected = tree->get_next_selected(selected);
Expand Down
2 changes: 1 addition & 1 deletion editor/import/3d/resource_importer_obj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ static Error _parse_obj(const String &p_path, List<Ref<ImporterMesh>> &r_meshes,
0x14c, // IMAGE_FILE_MACHINE_I386
0x200, // IMAGE_FILE_MACHINE_IA64
};
ERR_FAIL_COND_V_MSG(coff_header_machines.find(first_bytes) != -1, ERR_FILE_CORRUPT, vformat("Couldn't read OBJ file '%s', it seems to be binary, corrupted, or empty.", p_path));
ERR_FAIL_COND_V_MSG(coff_header_machines.has(first_bytes), ERR_FILE_CORRUPT, vformat("Couldn't read OBJ file '%s', it seems to be binary, corrupted, or empty.", p_path));
f->seek(0);

Ref<ImporterMesh> mesh;
Expand Down
8 changes: 4 additions & 4 deletions editor/import/3d/resource_importer_scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2086,12 +2086,12 @@ bool ResourceImporterScene::get_internal_option_visibility(InternalImportCategor
p_options.has("generate/physics") &&
p_options["generate/physics"].operator bool();

if (p_option.find("physics/") >= 0) {
if (p_option.contains("physics/")) {
// Show if need to generate collisions.
return generate_physics;
}

if (p_option.find("decomposition/") >= 0) {
if (p_option.contains("decomposition/")) {
// Show if need to generate collisions.
if (generate_physics &&
// Show if convex is enabled.
Expand Down Expand Up @@ -2285,8 +2285,8 @@ bool ResourceImporterScene::get_internal_option_update_view_required(InternalImp
if (
p_option == "generate/physics" ||
p_option == "physics/shape_type" ||
p_option.find("decomposition/") >= 0 ||
p_option.find("primitive/") >= 0) {
p_option.contains("decomposition/") ||
p_option.contains("primitive/")) {
return true;
}
} break;
Expand Down
2 changes: 1 addition & 1 deletion editor/plugins/script_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ void ScriptEditor::_add_recent_script(const String &p_path) {
}

Array rc = EditorSettings::get_singleton()->get_project_metadata("recent_files", "scripts", Array());
if (rc.find(p_path) != -1) {
if (rc.has(p_path)) {
rc.erase(p_path);
}
rc.push_front(p_path);
Expand Down
2 changes: 1 addition & 1 deletion editor/plugins/sprite_frames_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1312,7 +1312,7 @@ void SpriteFramesEditor::_update_library_impl() {
TreeItem *selected = nullptr;
for (const StringName &E : anim_names) {
String name = E;
if (searching && name.to_lower().find(searched_string) < 0) {
if (searching && !name.to_lower().contains(searched_string)) {
continue;
}
TreeItem *it = animations->create_item(anim_root);
Expand Down
2 changes: 1 addition & 1 deletion editor/rename_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ void RenameDialog::_error_handler(void *p_self, const char *p_func, const char *
String source_file = String::utf8(p_file);

// Only show first error that is related to "regex"
if (self->has_errors || source_file.find("regex") < 0) {
if (self->has_errors || !source_file.contains("regex")) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion editor/scene_tree_dock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1297,7 +1297,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
}

StringName name = node->get_name();
if (new_unique_names.find(name) != -1 || get_tree()->get_edited_scene_root()->get_node_or_null(UNIQUE_NODE_PREFIX + String(name)) != nullptr) {
if (new_unique_names.has(name) || get_tree()->get_edited_scene_root()->get_node_or_null(UNIQUE_NODE_PREFIX + String(name)) != nullptr) {
cant_be_set_unique_names.push_back(name);
} else {
new_unique_nodes.push_back(node);
Expand Down
2 changes: 1 addition & 1 deletion main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2993,7 +2993,7 @@ Error Main::setup2() {
// Dummy text driver cannot draw any text, making the editor unusable if selected.
continue;
}
if (!text_driver_options.is_empty() && text_driver_options.find(",") == -1) {
if (!text_driver_options.is_empty() && !text_driver_options.contains(",")) {
// Not the first option; add a comma before it as a separator for the property hint.
text_driver_options += ",";
}
Expand Down
2 changes: 1 addition & 1 deletion modules/csg/csg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,7 @@ int CSGBrushOperation::Build2DFaces::_add_vertex(const Vertex2D &p_vertex) {
}

void CSGBrushOperation::Build2DFaces::_add_vertex_idx_sorted(Vector<int> &r_vertex_indices, int p_new_vertex_index) {
if (p_new_vertex_index >= 0 && r_vertex_indices.find(p_new_vertex_index) == -1) {
if (p_new_vertex_index >= 0 && !r_vertex_indices.has(p_new_vertex_index)) {
ERR_FAIL_COND_MSG(p_new_vertex_index >= vertices.size(), "Invalid vertex index.");

// The first vertex.
Expand Down
2 changes: 1 addition & 1 deletion modules/gdscript/language_server/gdscript_workspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ const lsp::DocumentSymbol *GDScriptWorkspace::resolve_symbol(const lsp::TextDocu

} else {
ScriptLanguage::LookupResult ret;
if (symbol_identifier == "new" && parser->get_lines()[p_doc_pos.position.line].replace(" ", "").replace("\t", "").find("new(") > -1) {
if (symbol_identifier == "new" && parser->get_lines()[p_doc_pos.position.line].replace(" ", "").replace("\t", "").contains("new(")) {
symbol_identifier = "_init";
}
if (OK == GDScriptLanguage::get_singleton()->lookup_code(parser->get_text_for_lookup_symbol(pos, symbol_identifier, p_func_required), symbol_identifier, path, nullptr, ret)) {
Expand Down
2 changes: 1 addition & 1 deletion modules/gdscript/tests/test_lsp.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ Vector<InlineTestData> read_tests(const String &p_path) {
if (InlineTestData::try_parse(lines, i, d)) {
if (!d.name.is_empty()) {
// Safety check: names must be unique.
if (names.find(d.name) != -1) {
if (names.has(d.name)) {
FAIL(vformat("Duplicated name '%s' in '%s'. Names must be unique!", d.name, p_path));
}
names.append(d.name);
Expand Down
2 changes: 1 addition & 1 deletion modules/gltf/gltf_document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7032,7 +7032,7 @@ void GLTFDocument::_build_parent_hierachy(Ref<GLTFState> p_state) {
Vector<Ref<GLTFDocumentExtension>> GLTFDocument::all_document_extensions;

void GLTFDocument::register_gltf_document_extension(Ref<GLTFDocumentExtension> p_extension, bool p_first_priority) {
if (all_document_extensions.find(p_extension) == -1) {
if (!all_document_extensions.has(p_extension)) {
if (p_first_priority) {
all_document_extensions.insert(0, p_extension);
} else {
Expand Down
Loading

0 comments on commit a0dbdcc

Please sign in to comment.