Remove String::find_last (same as rfind)

This commit is contained in:
Stijn Hinlopen 2020-07-03 15:26:22 +02:00
parent fd5b6e1db2
commit 929b98d24b
26 changed files with 41 additions and 80 deletions

View file

@ -169,7 +169,7 @@ void EngineDebugger::initialize(const String &p_uri, bool p_skip_breakpoints, Ve
for (int i = 0; i < p_breakpoints.size(); i++) {
String bp = p_breakpoints[i];
int sp = bp.find_last(":");
int sp = bp.rfind(":");
ERR_CONTINUE_MSG(sp == -1, "Invalid breakpoint: '" + bp + "', expected file:line format.");
singleton_script_debugger->insert_breakpoint(bp.substr(sp + 1, bp.length()).to_int(), bp.substr(0, sp));

View file

@ -225,7 +225,7 @@ RemoteDebuggerPeer *RemoteDebuggerPeerTCP::create(const String &p_uri) {
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).to_int();
debug_host = debug_host.substr(0, sep_pos);
}

View file

@ -865,7 +865,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;
}

View file

@ -93,7 +93,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;
}

View file

@ -2280,18 +2280,6 @@ String String::substr(int p_from, int p_chars) const {
return s;
}
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;
}
int String::find(const String &p_str, int p_from) const {
if (p_from < 0) {
return -1;
@ -2582,7 +2570,7 @@ int String::rfindn(const String &p_str, int p_from) const {
}
bool String::ends_with(const String &p_string) const {
int pos = find_last(p_string);
int pos = rfind(p_string);
if (pos == -1) {
return false;
}
@ -3831,7 +3819,7 @@ String String::get_base_dir() const {
}
}
int sep = MAX(rs.find_last("/"), rs.find_last("\\"));
int sep = MAX(rs.rfind("/"), rs.rfind("\\"));
if (sep == -1) {
return base;
}
@ -3840,7 +3828,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;
}
@ -3849,8 +3837,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 "";
}
@ -3938,8 +3926,8 @@ String String::property_name_encode() 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;
}

View file

@ -202,7 +202,6 @@ public:
int find(const String &p_str, int p_from = 0) const; ///< return <0 if failed
int find(const char *p_str, int p_from = 0) const; ///< return <0 if failed
int find_char(const CharType &p_char, int p_from = 0) const; ///< return <0 if failed
int find_last(const String &p_str) const; ///< return <0 if failed
int findn(const String &p_str, int p_from = 0) const; ///< return <0 if failed, case insensitive
int rfind(const String &p_str, int p_from = -1) const; ///< return <0 if failed
int rfindn(const String &p_str, int p_from = -1) const; ///< return <0 if failed, case insensitive

View file

@ -244,7 +244,6 @@ struct _VariantCall {
VCALL_LOCALMEM3R(String, countn);
VCALL_LOCALMEM2R(String, substr);
VCALL_LOCALMEM2R(String, find);
VCALL_LOCALMEM1R(String, find_last);
VCALL_LOCALMEM2R(String, findn);
VCALL_LOCALMEM2R(String, rfind);
VCALL_LOCALMEM2R(String, rfindn);
@ -1780,7 +1779,6 @@ void register_variant_methods() {
ADDFUNC3R(STRING, INT, String, count, STRING, "what", INT, "from", INT, "to", varray(0, 0));
ADDFUNC3R(STRING, INT, String, countn, STRING, "what", INT, "from", INT, "to", varray(0, 0));
ADDFUNC1R(STRING, INT, String, find_last, STRING, "what", varray());
ADDFUNC2R(STRING, INT, String, findn, STRING, "what", INT, "from", varray(0));
ADDFUNC2R(STRING, INT, String, rfind, STRING, "what", INT, "from", varray(-1));
ADDFUNC2R(STRING, INT, String, rfindn, STRING, "what", INT, "from", varray(-1));

View file

@ -412,7 +412,8 @@
<argument index="1" name="from" type="int" default="0">
</argument>
<description>
Finds the first occurrence of a substring. Returns the starting position of the substring or [code]-1[/code] if not found. Optionally, the initial search index can be passed.
Returns the index of the [b]first[/b] case-sensitive occurrence of the specified string in this instance, or [code]-1[/code]. Optionally, the starting search index can be specified, continuing to the end of the string.
[b]Note:[/b] If you just want to know whether a string contains a substring, use the [code]in[/code] operator as follows:
[codeblock]
# Will evaluate to `false`.
@ -421,15 +422,6 @@
[/codeblock]
</description>
</method>
<method name="find_last">
<return type="int">
</return>
<argument index="0" name="what" type="String">
</argument>
<description>
Finds the last occurrence of a substring. Returns the starting position of the substring or [code]-1[/code] if not found.
</description>
</method>
<method name="findn">
<return type="int">
</return>
@ -438,7 +430,7 @@
<argument index="1" name="from" type="int" default="0">
</argument>
<description>
Finds the first occurrence of a substring, ignoring case. Returns the starting position of the substring or [code]-1[/code] if not found. Optionally, the initial search index can be passed.
Returns the index of the [b]first[/b] case-insensitive occurrence of the specified string in this instance, or [code]-1[/code]. Optionally, the starting search index can be specified, continuing to the end of the string.
</description>
</method>
<method name="format">
@ -801,7 +793,7 @@
<argument index="1" name="from" type="int" default="-1">
</argument>
<description>
Performs a case-sensitive search for a substring, but starts from the end of the string instead of the beginning.
Returns the index of the [b]last[/b] case-sensitive occurrence of the specified string in this instance, or [code]-1[/code]. Optionally, the starting search index can be specified, continuing to the beginning of the string.
</description>
</method>
<method name="rfindn">
@ -812,7 +804,7 @@
<argument index="1" name="from" type="int" default="-1">
</argument>
<description>
Performs a case-insensitive search for a substring, but starts from the end of the string instead of the beginning.
Returns the index of the [b]last[/b] case-insensitive occurrence of the specified string in this instance, or [code]-1[/code]. Optionally, the starting search index can be specified, continuing to the beginning of the string.
</description>
</method>
<method name="right">

View file

@ -3557,7 +3557,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) {
@ -3656,7 +3656,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);

View file

@ -159,7 +159,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) {

View file

@ -335,7 +335,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));
}

View file

@ -936,7 +936,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();
@ -951,7 +951,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 {

View file

@ -251,7 +251,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) {

View file

@ -1664,7 +1664,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(".");
@ -1679,7 +1679,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;

View file

@ -1688,7 +1688,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);
@ -1732,7 +1732,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);

View file

@ -710,11 +710,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) {

View file

@ -294,7 +294,7 @@ private:
// If the project name is empty or default, infer the project name from the selected folder name
if (project_name->get_text() == "" || project_name->get_text() == 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();

View file

@ -1666,7 +1666,7 @@ void ProjectSettingsEditor::_update_translations() {
PackedStringArray 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());

View file

@ -78,7 +78,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) {
@ -553,7 +553,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();

View file

@ -780,7 +780,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 {
@ -1992,7 +1992,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);

View file

@ -277,13 +277,6 @@ godot_int GDAPI godot_string_findn_from(const godot_string *p_self, godot_string
return self->findn(*what, p_from);
}
godot_int GDAPI godot_string_find_last(const godot_string *p_self, godot_string p_what) {
const String *self = (const String *)p_self;
String *what = (String *)&p_what;
return self->find_last(*what);
}
godot_string GDAPI godot_string_format(const godot_string *p_self, const godot_variant *p_values) {
const String *self = (const String *)p_self;
const Variant *values = (const Variant *)p_values;

View file

@ -3824,14 +3824,6 @@
["godot_int", "p_from"]
]
},
{
"name": "godot_string_find_last",
"return_type": "godot_int",
"arguments": [
["const godot_string *", "p_self"],
["godot_string", "p_what"]
]
},
{
"name": "godot_string_format",
"return_type": "godot_string",

View file

@ -111,7 +111,6 @@ godot_int GDAPI godot_string_findmk_from(const godot_string *p_self, const godot
godot_int GDAPI godot_string_findmk_from_in_place(const godot_string *p_self, const godot_array *p_keys, godot_int p_from, godot_int *r_key);
godot_int GDAPI godot_string_findn(const godot_string *p_self, godot_string p_what);
godot_int GDAPI godot_string_findn_from(const godot_string *p_self, godot_string p_what, godot_int p_from);
godot_int GDAPI godot_string_find_last(const godot_string *p_self, godot_string p_what);
godot_string GDAPI godot_string_format(const godot_string *p_self, const godot_variant *p_values);
godot_string GDAPI godot_string_format_with_custom_placeholder(const godot_string *p_self, const godot_variant *p_values, const char *p_placeholder);
godot_string GDAPI godot_string_hex_encode_buffer(const uint8_t *p_buffer, godot_int p_len);

View file

@ -66,7 +66,7 @@ Error WebSocketClient::connect_to_url(String p_url, const Vector<String> p_proto
}
// Port
p_len = host.find_last(":");
p_len = host.rfind(":");
if (p_len != -1 && p_len == host.find(":")) {
port = host.substr(p_len, host.length() - p_len).to_int();
host = host.substr(0, p_len);

View file

@ -1334,7 +1334,7 @@ class EditorExportPlatformAndroid : public EditorExportPlatform {
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);

View file

@ -604,7 +604,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)) {
@ -617,7 +617,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 {