diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp index 957f22d855e..03505227204 100644 --- a/core/io/resource_loader.cpp +++ b/core/io/resource_loader.cpp @@ -732,7 +732,7 @@ String ResourceLoader::_path_remap(const String &p_path, bool *r_translation_rem bool near_match = false; for (int i = 0; i < res_remaps.size(); i++) { - int split = res_remaps[i].find_last(":"); + int split = res_remaps[i].rfind(":"); if (split == -1) { continue; } diff --git a/core/project_settings.cpp b/core/project_settings.cpp index ecff1becb71..6c6e2dc2f1c 100644 --- a/core/project_settings.cpp +++ b/core/project_settings.cpp @@ -99,7 +99,7 @@ String ProjectSettings::localize_path(const String &p_path) const { } else { memdelete(dir); - int sep = path.find_last("/"); + int sep = path.rfind("/"); if (sep == -1) { return "res://" + path; }; diff --git a/core/ustring.cpp b/core/ustring.cpp index 6eed672bb23..fa7fdbbc65e 100644 --- a/core/ustring.cpp +++ b/core/ustring.cpp @@ -2443,15 +2443,7 @@ String String::substr(int p_from, int p_chars) const { } int String::find_last(const String &p_str) const { - int pos = -1; - int findfrom = 0; - int findres = -1; - while ((findres = find(p_str, findfrom)) != -1) { - pos = findres; - findfrom = pos + 1; - } - - return pos; + return rfind(p_str); } int String::find(const String &p_str, int p_from) const { @@ -4062,7 +4054,7 @@ String String::get_base_dir() const { } String String::get_file() const { - int sep = MAX(find_last("/"), find_last("\\")); + int sep = MAX(rfind("/"), rfind("\\")); if (sep == -1) { return *this; } @@ -4071,8 +4063,8 @@ String String::get_file() const { } String String::get_extension() const { - int pos = find_last("."); - if (pos < 0 || pos < MAX(find_last("/"), find_last("\\"))) { + int pos = rfind("."); + if (pos < 0 || pos < MAX(rfind("/"), rfind("\\"))) { return ""; } @@ -4171,8 +4163,8 @@ String String::validate_node_name() const { } String String::get_basename() const { - int pos = find_last("."); - if (pos < 0 || pos < MAX(find_last("/"), find_last("\\"))) { + int pos = rfind("."); + if (pos < 0 || pos < MAX(rfind("/"), rfind("\\"))) { return *this; } diff --git a/editor/animation_track_editor.cpp b/editor/animation_track_editor.cpp index d802c13856a..22713baa1d8 100644 --- a/editor/animation_track_editor.cpp +++ b/editor/animation_track_editor.cpp @@ -3639,7 +3639,7 @@ void AnimationTrackEditor::insert_node_value_key(Node *p_node, const String &p_p if (track_path == np) { value = p_value; //all good } else { - int sep = track_path.find_last(":"); + int sep = track_path.rfind(":"); if (sep != -1) { String base_path = track_path.substr(0, sep); if (base_path == np) { @@ -3738,7 +3738,7 @@ void AnimationTrackEditor::insert_value_key(const String &p_property, const Vari value = p_value; //all good } else { String tpath = animation->track_get_path(i); - int index = tpath.find_last(":"); + int index = tpath.rfind(":"); if (NodePath(tpath.substr(0, index + 1)) == np) { String subindex = tpath.substr(index + 1, tpath.length() - index); value = p_value.get(subindex); diff --git a/editor/editor_asset_installer.cpp b/editor/editor_asset_installer.cpp index c7952806e36..b017d0c2a3e 100644 --- a/editor/editor_asset_installer.cpp +++ b/editor/editor_asset_installer.cpp @@ -224,7 +224,7 @@ void EditorAssetInstaller::open(const String &p_path, int p_depth) { isdir = true; } - int pp = path.find_last("/"); + int pp = path.rfind("/"); TreeItem *parent; if (pp == -1) { diff --git a/editor/editor_feature_profile.cpp b/editor/editor_feature_profile.cpp index 30bba1e0bad..60f5723458c 100644 --- a/editor/editor_feature_profile.cpp +++ b/editor/editor_feature_profile.cpp @@ -359,7 +359,7 @@ void EditorFeatureProfileManager::_update_profile_list(const String &p_select_pr } if (!d->current_is_dir()) { - int last_pos = f.find_last(".profile"); + int last_pos = f.rfind(".profile"); if (last_pos != -1) { profiles.push_back(f.substr(0, last_pos)); } diff --git a/editor/editor_file_dialog.cpp b/editor/editor_file_dialog.cpp index 4afc10a5158..afcc1ec600e 100644 --- a/editor/editor_file_dialog.cpp +++ b/editor/editor_file_dialog.cpp @@ -944,7 +944,7 @@ void EditorFileDialog::set_current_file(const String &p_file) { file->set_text(p_file); update_dir(); invalidate(); - int lp = p_file.find_last("."); + int lp = p_file.rfind("."); if (lp != -1) { file->select(0, lp); file->grab_focus(); @@ -958,7 +958,7 @@ void EditorFileDialog::set_current_path(const String &p_path) { if (!p_path.size()) { return; } - int pos = MAX(p_path.find_last("/"), p_path.find_last("\\")); + int pos = MAX(p_path.rfind("/"), p_path.rfind("\\")); if (pos == -1) { set_current_file(p_path); } else { diff --git a/editor/editor_folding.cpp b/editor/editor_folding.cpp index 80c805e91ff..22e07aa103d 100644 --- a/editor/editor_folding.cpp +++ b/editor/editor_folding.cpp @@ -249,7 +249,7 @@ void EditorFolding::_do_object_unfolds(Object *p_object, Set &resources) { } } } else { //path - int last = E->get().name.find_last("/"); + int last = E->get().name.rfind("/"); if (last != -1) { bool can_revert = EditorPropertyRevert::can_property_revert(p_object, E->get().name); if (can_revert) { diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp index 8a8e5052561..78c9471698a 100644 --- a/editor/editor_inspector.cpp +++ b/editor/editor_inspector.cpp @@ -1544,7 +1544,7 @@ void EditorInspector::update_tree() { basename = group + "/" + basename; } - String name = (basename.find("/") != -1) ? basename.right(basename.find_last("/") + 1) : basename; + String name = (basename.find("/") != -1) ? basename.right(basename.rfind("/") + 1) : basename; if (capitalize_paths) { int dot = name.find("."); @@ -1559,7 +1559,7 @@ void EditorInspector::update_tree() { } } - String path = basename.left(basename.find_last("/")); + String path = basename.left(basename.rfind("/")); if (use_filter && filter != "") { String cat = path; diff --git a/editor/filesystem_dock.cpp b/editor/filesystem_dock.cpp index 25c7dc3b5f5..8d75b0275ea 100644 --- a/editor/filesystem_dock.cpp +++ b/editor/filesystem_dock.cpp @@ -1819,7 +1819,7 @@ void FileSystemDock::_file_option(int p_option, const Vector &p_selected String name = to_rename.path.get_file(); rename_dialog->set_title(TTR("Renaming file:") + " " + name); rename_dialog_text->set_text(name); - rename_dialog_text->select(0, name.find_last(".")); + rename_dialog_text->select(0, name.rfind(".")); } else { String name = to_rename.path.substr(0, to_rename.path.length() - 1).get_file(); rename_dialog->set_title(TTR("Renaming folder:") + " " + name); @@ -1863,7 +1863,7 @@ void FileSystemDock::_file_option(int p_option, const Vector &p_selected String name = to_duplicate.path.get_file(); duplicate_dialog->set_title(TTR("Duplicating file:") + " " + name); duplicate_dialog_text->set_text(name); - duplicate_dialog_text->select(0, name.find_last(".")); + duplicate_dialog_text->select(0, name.rfind(".")); } else { String name = to_duplicate.path.substr(0, to_duplicate.path.length() - 1).get_file(); duplicate_dialog->set_title(TTR("Duplicating folder:") + " " + name); diff --git a/editor/plugins/animation_player_editor_plugin.cpp b/editor/plugins/animation_player_editor_plugin.cpp index 166a09cacad..0ac9a1c3bb3 100644 --- a/editor/plugins/animation_player_editor_plugin.cpp +++ b/editor/plugins/animation_player_editor_plugin.cpp @@ -722,11 +722,11 @@ void AnimationPlayerEditor::_dialog_action(String p_file) { Ref res = ResourceLoader::load(p_file, "Animation"); ERR_FAIL_COND_MSG(res.is_null(), "Cannot load Animation from file '" + p_file + "'."); ERR_FAIL_COND_MSG(!res->is_class("Animation"), "Loaded resource from file '" + p_file + "' is not Animation."); - if (p_file.find_last("/") != -1) { - p_file = p_file.substr(p_file.find_last("/") + 1, p_file.length()); + if (p_file.rfind("/") != -1) { + p_file = p_file.substr(p_file.rfind("/") + 1, p_file.length()); } - if (p_file.find_last("\\") != -1) { - p_file = p_file.substr(p_file.find_last("\\") + 1, p_file.length()); + if (p_file.rfind("\\") != -1) { + p_file = p_file.substr(p_file.rfind("\\") + 1, p_file.length()); } if (p_file.find(".") != -1) { diff --git a/editor/project_manager.cpp b/editor/project_manager.cpp index cc46fe79e75..19469284646 100644 --- a/editor/project_manager.cpp +++ b/editor/project_manager.cpp @@ -299,7 +299,7 @@ private: // If the project name is empty or default, infer the project name from the selected folder name if (project_name->get_text().strip_edges() == "" || project_name->get_text().strip_edges() == TTR("New Game Project")) { sp = sp.replace("\\", "/"); - int lidx = sp.find_last("/"); + int lidx = sp.rfind("/"); if (lidx != -1) { sp = sp.substr(lidx + 1, sp.length()).capitalize(); diff --git a/editor/project_settings_editor.cpp b/editor/project_settings_editor.cpp index f089abf67c7..85ffa50b852 100644 --- a/editor/project_settings_editor.cpp +++ b/editor/project_settings_editor.cpp @@ -1655,7 +1655,7 @@ void ProjectSettingsEditor::_update_translations() { PoolStringArray selected = remaps[keys[i]]; for (int j = 0; j < selected.size(); j++) { String s2 = selected[j]; - int qp = s2.find_last(":"); + int qp = s2.rfind(":"); String path = s2.substr(0, qp); String locale = s2.substr(qp + 1, s2.length()); diff --git a/editor/script_create_dialog.cpp b/editor/script_create_dialog.cpp index 6d1af0372d4..b6f997ad942 100644 --- a/editor/script_create_dialog.cpp +++ b/editor/script_create_dialog.cpp @@ -75,7 +75,7 @@ void ScriptCreateDialog::_notification(int p_what) { void ScriptCreateDialog::_path_hbox_sorted() { if (is_visible()) { - int filename_start_pos = initial_bp.find_last("/") + 1; + int filename_start_pos = initial_bp.rfind("/") + 1; int filename_end_pos = initial_bp.length(); if (!is_built_in) { @@ -554,7 +554,7 @@ void ScriptCreateDialog::_file_selected(const String &p_file) { _path_changed(p); String filename = p.get_file().get_basename(); - int select_start = p.find_last(filename); + int select_start = p.rfind(filename); file_path->select(select_start, select_start + filename.length()); file_path->set_cursor_position(select_start + filename.length()); file_path->grab_focus(); diff --git a/main/main.cpp b/main/main.cpp index 29d06e84e06..e0df6794ec4 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -772,7 +772,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph } else if (I->get().ends_with("project.godot")) { String path; String file = I->get(); - int sep = MAX(file.find_last("/"), file.find_last("\\")); + int sep = MAX(file.rfind("/"), file.rfind("\\")); if (sep == -1) { path = "."; } else { @@ -944,7 +944,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph ScriptDebuggerRemote *sdr = memnew(ScriptDebuggerRemote); uint16_t debug_port = 6007; if (debug_host.find(":") != -1) { - int sep_pos = debug_host.find_last(":"); + int sep_pos = debug_host.rfind(":"); debug_port = debug_host.substr(sep_pos + 1, debug_host.length()).to_int(); debug_host = debug_host.substr(0, sep_pos); } @@ -967,7 +967,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph for (int i = 0; i < breakpoints.size(); i++) { String bp = breakpoints[i]; - int sp = bp.find_last(":"); + int sp = bp.rfind(":"); ERR_CONTINUE_MSG(sp == -1, "Invalid breakpoint: '" + bp + "', expected file:line format."); script_debugger->insert_breakpoint(bp.substr(sp + 1, bp.length()).to_int(), bp.substr(0, sp)); @@ -2034,7 +2034,7 @@ bool Main::start() { local_game_path = "res://" + local_game_path; } else { - int sep = local_game_path.find_last("/"); + int sep = local_game_path.rfind("/"); if (sep == -1) { DirAccess *da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); diff --git a/modules/gdnative/gdnative/string.cpp b/modules/gdnative/gdnative/string.cpp index 31bc5b23872..178b4619dd1 100644 --- a/modules/gdnative/gdnative/string.cpp +++ b/modules/gdnative/gdnative/string.cpp @@ -275,7 +275,7 @@ godot_int GDAPI godot_string_find_last(const godot_string *p_self, godot_string const String *self = (const String *)p_self; String *what = (String *)&p_what; - return self->find_last(*what); + return self->rfind(*what); } godot_string GDAPI godot_string_format(const godot_string *p_self, const godot_variant *p_values) { diff --git a/platform/android/export/export_plugin.cpp b/platform/android/export/export_plugin.cpp index 7664fc255ae..05ec6571b0d 100644 --- a/platform/android/export/export_plugin.cpp +++ b/platform/android/export/export_plugin.cpp @@ -1406,7 +1406,7 @@ void EditorExportPlatformAndroid::_fix_resources(const Ref & str = get_project_name(package_name); } else { - String lang = str.substr(str.find_last("-") + 1, str.length()).replace("-", "_"); + String lang = str.substr(str.rfind("-") + 1, str.length()).replace("-", "_"); String prop = "application/config/name_" + lang; if (ProjectSettings::get_singleton()->has_setting(prop)) { str = ProjectSettings::get_singleton()->get(prop); diff --git a/scene/gui/file_dialog.cpp b/scene/gui/file_dialog.cpp index c294e492180..ae58e0b41e6 100644 --- a/scene/gui/file_dialog.cpp +++ b/scene/gui/file_dialog.cpp @@ -601,7 +601,7 @@ void FileDialog::set_current_file(const String &p_file) { file->set_text(p_file); update_dir(); invalidate(); - int lp = p_file.find_last("."); + int lp = p_file.rfind("."); if (lp != -1) { file->select(0, lp); if (file->is_inside_tree() && !get_tree()->is_node_being_edited(file)) { @@ -613,7 +613,7 @@ void FileDialog::set_current_path(const String &p_path) { if (!p_path.size()) { return; } - int pos = MAX(p_path.find_last("/"), p_path.find_last("\\")); + int pos = MAX(p_path.rfind("/"), p_path.rfind("\\")); if (pos == -1) { set_current_file(p_path); } else {