mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-01-03 15:16:14 +00:00
AK: Add StringView::count(char)
This commit is contained in:
committed by
Ali Mohammad Pur
parent
b40ab55830
commit
3556c27d2d
@@ -593,6 +593,16 @@ size_t count(StringView str, StringView needle)
|
|||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t count(StringView str, char needle)
|
||||||
|
{
|
||||||
|
size_t count = 0;
|
||||||
|
for (size_t i = 0; i < str.length(); ++i) {
|
||||||
|
if (str[i] == needle)
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -107,6 +107,7 @@ DeprecatedString replace(StringView, StringView needle, StringView replacement,
|
|||||||
ErrorOr<String> replace(String const&, StringView needle, StringView replacement, ReplaceMode);
|
ErrorOr<String> replace(String const&, StringView needle, StringView replacement, ReplaceMode);
|
||||||
|
|
||||||
size_t count(StringView, StringView needle);
|
size_t count(StringView, StringView needle);
|
||||||
|
size_t count(StringView, char needle);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -330,6 +330,11 @@ public:
|
|||||||
return StringUtils::count(*this, needle);
|
return StringUtils::count(*this, needle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] size_t count(char needle) const
|
||||||
|
{
|
||||||
|
return StringUtils::count(*this, needle);
|
||||||
|
}
|
||||||
|
|
||||||
template<typename... Ts>
|
template<typename... Ts>
|
||||||
[[nodiscard]] ALWAYS_INLINE constexpr bool is_one_of(Ts&&... strings) const
|
[[nodiscard]] ALWAYS_INLINE constexpr bool is_one_of(Ts&&... strings) const
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user