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:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user