mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 20:47:45 +00:00
AK: Make String::matches() capable of reporting match positions too
Also, rewrite StringUtils::match(), because the old implementation was fairly broken, e.g. "acdcxb" would *not* match "a*?b".
This commit is contained in:
parent
2d6d1ca67f
commit
0801b1fada
7 changed files with 86 additions and 33 deletions
|
@ -42,9 +42,23 @@ enum class TrimMode {
|
|||
Both
|
||||
};
|
||||
|
||||
struct MaskSpan {
|
||||
size_t start;
|
||||
size_t length;
|
||||
|
||||
bool operator==(const MaskSpan& other) const
|
||||
{
|
||||
return start == other.start && length == other.length;
|
||||
}
|
||||
bool operator!=(const MaskSpan& other) const
|
||||
{
|
||||
return !(*this == other);
|
||||
}
|
||||
};
|
||||
|
||||
namespace StringUtils {
|
||||
|
||||
bool matches(const StringView& str, const StringView& mask, CaseSensitivity = CaseSensitivity::CaseInsensitive);
|
||||
bool matches(const StringView& str, const StringView& mask, CaseSensitivity = CaseSensitivity::CaseInsensitive, Vector<MaskSpan>* match_spans = nullptr);
|
||||
Optional<int> convert_to_int(const StringView&);
|
||||
Optional<unsigned> convert_to_uint(const StringView&);
|
||||
Optional<unsigned> convert_to_uint_from_hex(const StringView&);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue