1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-14 13:41:12 +00:00

Clean up some uses of String::substr

Cases where the end position is either equvalent to the default or past
the end of the string.
This commit is contained in:
A Thousand Ships
2025-02-26 11:41:11 +01:00
parent f2cc3f1275
commit 5113022dfe
54 changed files with 123 additions and 123 deletions

View File

@@ -238,7 +238,7 @@ Error String::parse_url(String &r_scheme, String &r_host, int &r_port, String &r
}
if (is_scheme_valid) {
r_scheme = base.substr(0, pos + 3).to_lower();
base = base.substr(pos + 3, base.length() - pos - 3);
base = base.substr(pos + 3);
}
}
pos = base.find_char('#');
@@ -250,14 +250,14 @@ Error String::parse_url(String &r_scheme, String &r_host, int &r_port, String &r
pos = base.find_char('/');
// Path
if (pos != -1) {
r_path = base.substr(pos, base.length() - pos);
r_path = base.substr(pos);
base = base.substr(0, pos);
}
// Host
pos = base.find_char('@');
if (pos != -1) {
// Strip credentials
base = base.substr(pos + 1, base.length() - pos - 1);
base = base.substr(pos + 1);
}
if (base.begins_with("[")) {
// Literal IPv6
@@ -266,7 +266,7 @@ Error String::parse_url(String &r_scheme, String &r_host, int &r_port, String &r
return ERR_INVALID_PARAMETER;
}
r_host = base.substr(1, pos - 1);
base = base.substr(pos + 1, base.length() - pos - 1);
base = base.substr(pos + 1);
} else {
// Anything else
if (base.get_slice_count(":") > 2) {
@@ -278,7 +278,7 @@ Error String::parse_url(String &r_scheme, String &r_host, int &r_port, String &r
base = "";
} else {
r_host = base.substr(0, pos);
base = base.substr(pos, base.length() - pos);
base = base.substr(pos);
}
}
if (r_host.is_empty()) {
@@ -287,7 +287,7 @@ Error String::parse_url(String &r_scheme, String &r_host, int &r_port, String &r
r_host = r_host.to_lower();
// Port
if (base.begins_with(":")) {
base = base.substr(1, base.length() - 1);
base = base.substr(1);
if (!base.is_valid_int()) {
return ERR_INVALID_PARAMETER;
}
@@ -4861,7 +4861,7 @@ String String::pad_zeros(int p_digits) const {
String String::trim_prefix(const String &p_prefix) const {
String s = *this;
if (s.begins_with(p_prefix)) {
return s.substr(p_prefix.length(), s.length() - p_prefix.length());
return s.substr(p_prefix.length());
}
return s;
}
@@ -4870,7 +4870,7 @@ String String::trim_prefix(const char *p_prefix) const {
String s = *this;
if (s.begins_with(p_prefix)) {
int prefix_length = strlen(p_prefix);
return s.substr(prefix_length, s.length() - prefix_length);
return s.substr(prefix_length);
}
return s;
}
@@ -5030,8 +5030,8 @@ String String::path_to(const String &p_path) const {
return p_path; //impossible to do this
}
src = src.substr(src_begin.length(), src.length());
dst = dst.substr(dst_begin.length(), dst.length());
src = src.substr(src_begin.length());
dst = dst.substr(dst_begin.length());
}
//remove leading and trailing slash and split