mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 17:57:35 +00:00
AK: Add StringView::find_last_not
This commit is contained in:
parent
48aea321c5
commit
9718667bcf
3 changed files with 11 additions and 0 deletions
|
@ -388,6 +388,15 @@ Optional<size_t> find_last(StringView haystack, char needle)
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Optional<size_t> find_last_not(StringView haystack, char needle)
|
||||||
|
{
|
||||||
|
for (size_t i = haystack.length(); i > 0; --i) {
|
||||||
|
if (haystack[i - 1] != needle)
|
||||||
|
return i - 1;
|
||||||
|
}
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
Vector<size_t> find_all(StringView haystack, StringView needle)
|
Vector<size_t> find_all(StringView haystack, StringView needle)
|
||||||
{
|
{
|
||||||
Vector<size_t> positions;
|
Vector<size_t> positions;
|
||||||
|
|
|
@ -74,6 +74,7 @@ StringView trim_whitespace(StringView string, TrimMode mode);
|
||||||
Optional<size_t> find(StringView haystack, char needle, size_t start = 0);
|
Optional<size_t> find(StringView haystack, char needle, size_t start = 0);
|
||||||
Optional<size_t> find(StringView haystack, StringView needle, size_t start = 0);
|
Optional<size_t> find(StringView haystack, StringView needle, size_t start = 0);
|
||||||
Optional<size_t> find_last(StringView haystack, char needle);
|
Optional<size_t> find_last(StringView haystack, char needle);
|
||||||
|
Optional<size_t> find_last_not(StringView haystack, char needle);
|
||||||
Vector<size_t> find_all(StringView haystack, StringView needle);
|
Vector<size_t> find_all(StringView haystack, StringView needle);
|
||||||
enum class SearchDirection {
|
enum class SearchDirection {
|
||||||
Forward,
|
Forward,
|
||||||
|
|
|
@ -107,6 +107,7 @@ public:
|
||||||
}
|
}
|
||||||
[[nodiscard]] Optional<size_t> find(StringView needle, size_t start = 0) const { return StringUtils::find(*this, needle, start); }
|
[[nodiscard]] Optional<size_t> find(StringView needle, size_t start = 0) const { return StringUtils::find(*this, needle, start); }
|
||||||
[[nodiscard]] Optional<size_t> find_last(char needle) const { return StringUtils::find_last(*this, needle); }
|
[[nodiscard]] Optional<size_t> find_last(char needle) const { return StringUtils::find_last(*this, needle); }
|
||||||
|
[[nodiscard]] Optional<size_t> find_last_not(char needle) const { return StringUtils::find_last_not(*this, needle); }
|
||||||
// FIXME: Implement find_last(StringView) for API symmetry.
|
// FIXME: Implement find_last(StringView) for API symmetry.
|
||||||
|
|
||||||
[[nodiscard]] Vector<size_t> find_all(StringView needle) const;
|
[[nodiscard]] Vector<size_t> find_all(StringView needle) const;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue