Harmonize String, Vector and LocalVector find and rfind.

Use `Span::find` for `LocalVector::find`, accepting negative `p_from`.
Return `-1` for invalid `p_from` values in `rfind`.
Accept negative values for `p_from` in `find`, starting from the back.
This commit is contained in:
Lukas Tenbrink
2025-03-17 20:37:46 +01:00
parent 9e6ee9c5c3
commit fde71e0382
4 changed files with 42 additions and 26 deletions
+12
View File
@@ -3329,6 +3329,12 @@ int String::find(const char *p_str, int p_from) const {
}
int String::find_char(char32_t p_char, int p_from) const {
if (p_from < 0) {
p_from = length() + p_from;
}
if (p_from < 0 || p_from >= length()) {
return -1;
}
return span().find(p_char, p_from);
}
@@ -3566,6 +3572,12 @@ int String::rfind(const char *p_str, int p_from) const {
}
int String::rfind_char(char32_t p_char, int p_from) const {
if (p_from < 0) {
p_from = length() + p_from;
}
if (p_from < 0 || p_from >= length()) {
return -1;
}
return span().rfind(p_char, p_from);
}