diff options
author | AnotherTest <ali.mpfard@gmail.com> | 2020-10-25 09:04:39 +0330 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-10-29 11:53:01 +0100 |
commit | 0801b1fada4d1eacdde3dc4aff04b9ee9eb73bf8 (patch) | |
tree | b9fefba7e71e8178cc5c43088e185278a760ff64 /AK/StringUtils.h | |
parent | 2d6d1ca67f4f5c8c9dbf40b24675810a6e778c78 (diff) | |
download | serenity-0801b1fada4d1eacdde3dc4aff04b9ee9eb73bf8.zip |
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".
Diffstat (limited to 'AK/StringUtils.h')
-rw-r--r-- | AK/StringUtils.h | 16 |
1 files changed, 15 insertions, 1 deletions
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<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&); |