Merge pull request #56630 from Pineapple/replace-find-last
This commit is contained in:
commit
c938104a88
18 changed files with 35 additions and 43 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -249,7 +249,7 @@ void EditorFolding::_do_object_unfolds(Object *p_object, Set<RES> &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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -1819,7 +1819,7 @@ void FileSystemDock::_file_option(int p_option, const Vector<String> &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<String> &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);
|
||||
|
|
|
@ -722,11 +722,11 @@ void AnimationPlayerEditor::_dialog_action(String p_file) {
|
|||
Ref<Resource> 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) {
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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());
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -1406,7 +1406,7 @@ void EditorExportPlatformAndroid::_fix_resources(const Ref<EditorExportPreset> &
|
|||
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);
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue