4#ifndef QSTATICLATIN1STRINGMATCHER_H
5#define QSTATICLATIN1STRINGMATCHER_H
11#include <QtCore/q20algorithm.h>
12#include <QtCore/qlatin1stringmatcher.h>
13#include <QtCore/qstring.h>
18# define QT_STATIC_BOYER_MOORE_NOT_SUPPORTED
21template <
class RandomIt1,
22 class Hash = std::hash<typename std::iterator_traits<RandomIt1>::value_type>,
23 class BinaryPredicate = std::equal_to<>>
29 const size_t n = std::distance(pat_first, pat_last);
30 constexpr auto uchar_max = (std::numeric_limits<uchar>::max)();
32 q20::fill(std::begin(m_skiptable), std::end(m_skiptable), max);
34 RandomIt1
pattern = std::next(pat_first,
n - max);
36 m_skiptable[hf(*
pattern++)] = max;
39 template <
class RandomIt2>
41 RandomIt1 pat_last)
const
49 auto pat_length = std::distance(pat_first, pat_last);
53 auto haystack_length = std::distance(
first, last);
54 if (haystack_length < pat_length)
55 return R{ last, last };
58 RandomIt2 current =
first + pl_minus_one;
61 while (current < last - skip) {
63 skip = m_skiptable[hf(*current)];
66 while (skip < pat_length) {
67 if (!pred(hf(*(current - skip)), hf(pat_first[pl_minus_one - skip])))
71 if (skip > pl_minus_one) {
72 auto match = current + 1 - skip;
78 if (m_skiptable[hf(*(current - skip))] == pat_length)
79 skip = pat_length - skip;
85 return R{ last, last };
89 alignas(16)
uchar m_skiptable[256];
93template <Qt::CaseSensitivity CS,
size_t N>
97 "QStaticLatin1StringMatcher makes no sense for finding a single-char pattern");
106 : m_pattern(patternToMatch),
107 m_searcher(patternToMatch.begin(), patternToMatch.begin() + N - 1)
112 {
return indexIn_helper(haystack, from); }
115 {
return indexIn_helper(haystack, from); }
118 template <
typename String>
119 constexpr qsizetype indexIn_helper(String haystack,
qsizetype from = 0) const noexcept
121 static_assert(QtPrivate::isLatin1OrUtf16View<String>);
123 if (from >= haystack.size())
126 const auto start = [haystack]()
constexpr {
127 if constexpr (std::is_same_v<String, QStringView>)
128 return haystack.utf16();
130 return haystack.begin();
133 const auto end =
start + haystack.size();
135 return r.begin ==
end ? -1 : std::distance(
start,
r.begin);
142 return QStaticLatin1StringMatcher<Qt::CaseSensitive, N>(
150 return QStaticLatin1StringMatcher<Qt::CaseInsensitive, N>(
constexpr const_iterator end() const noexcept
constexpr const_iterator begin() const noexcept
constexpr qsizetype indexIn(QStringView haystack, qsizetype from=0) const noexcept
constexpr qsizetype indexIn(QLatin1StringView haystack, qsizetype from=0) const noexcept
constexpr QStaticLatin1StringMatcher(QLatin1StringView patternToMatch) noexcept
constexpr auto operator()(RandomIt2 first, RandomIt2 last, RandomIt1 pat_first, RandomIt1 pat_last) const
constexpr q_boyer_moore_searcher(RandomIt1 pat_first, RandomIt1 pat_last)
Combined button and popup list for selecting options.
constexpr void fill(ForwardIterator first, ForwardIterator last, const Value &value)
QtPrivate::QRegularExpressionMatchIteratorRangeBasedForIterator begin(const QRegularExpressionMatchIterator &iterator)
constexpr auto qMakeStaticCaseSensitiveLatin1StringMatcher(const char(&patternToMatch)[N]) noexcept
constexpr auto qMakeStaticCaseInsensitiveLatin1StringMatcher(const char(&patternToMatch)[N]) noexcept
static bool match(const uchar *found, uint foundLen, const char *target, uint targetLen)