From 0801b1fada4d1eacdde3dc4aff04b9ee9eb73bf8 Mon Sep 17 00:00:00 2001 From: AnotherTest Date: Sun, 25 Oct 2020 09:04:39 +0330 Subject: 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". --- AK/StringUtils.h | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'AK/StringUtils.h') diff --git a/AK/StringUtils.h b/AK/StringUtils.h index 7c532175c3..849be54d18 100644 --- a/AK/StringUtils.h +++ b/AK/StringUtils.h @@ -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* match_spans = nullptr); Optional convert_to_int(const StringView&); Optional convert_to_uint(const StringView&); Optional convert_to_uint_from_hex(const StringView&); -- cgit v1.2.3