Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qstaticlatin1stringmatcher.qdoc
Go to the documentation of this file.
1// Copyright (C) 2023 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3// Qt-Security score:insignificant reason:docs
4
5/*! \class QStaticLatin1StringMatcher
6 \inmodule QtCore
7 \brief The QStaticLatin1StringMatcher class is a compile-time version
8 of QLatin1StringMatcher.
9
10 \since 6.7
11 \ingroup tools
12 \ingroup string-processing
13
14 QStaticLatin1StringMatcher<CS, N> is a template class where \a CS is
15 the Qt::CaseSensitivity to use for matching and \a N is the length of the
16 pattern to search for (including the null terminator for string literals).
17
18 This class is useful when your code needs to search efficiently
19 in Latin-1 strings for a substring that's known at compile-time.
20 This is common, for example, in parsers. Using a matcher
21 object's indexIn() is faster than using the indexOf() member method of
22 the string you are searching in, especially when the string to
23 be found will be searched for repeatedly or within a large
24 Latin-1 string that may contain many matches to prefixes of the
25 substring to be found.
26
27 Unlike QLatin1StringMatcher, this class calculates the internal
28 representation at \e{compile-time}, so it can be beneficial even if you
29 are doing one-off Latin-1 string matches.
30
31 Create the QStaticLatin1StringMatcher by calling
32 qMakeStaticCaseSensitiveLatin1StringMatcher() or
33 qMakeStaticCaseInsensitiveLatin1StringMatcher() passing the Latin-1
34 string to search for as a C string literal. Store the return value of
35 that function in a \c{static constexpr auto} variable, so you don't
36 need to pass the \c{N} template parameter explicitly.
37
38 Then call indexIn() on the QLatin1StringView in which you want to search,
39 just like with QLatin1StringMatcher.
40
41 Since this class is designed to do all the up-front calculations at
42 compile-time, it does not offer setPattern() or setCaseSensitivity()
43 methods.
44
45 \note INTEGRITY operating system is currently not supported.
46
47 \sa QLatin1StringMatcher, QStaticByteArrayMatcher, QByteArrayMatcher
48*/
49
50/*!
51 \fn template<Qt::CaseSensitivity CS, size_t N> constexpr qsizetype QStaticLatin1StringMatcher<CS, N>::indexIn(QLatin1StringView haystack, qsizetype from) const
52 \fn template<Qt::CaseSensitivity CS, size_t N> constexpr qsizetype QStaticLatin1StringMatcher<CS, N>::indexIn(QStringView haystack, qsizetype from) const
53
54 Searches the QLatin1StringView \a haystack, from byte position \a from
55 (default 0, i.e. from the first byte), for QLatin1StringView pattern()
56 that was set in the constructor. Using the case sensitivity that was also
57 set in the constructor.
58
59 Returns the position where the pattern() matched in \a haystack, or -1 if no match was found.
60*/
61
62/*!
63 \fn template<size_t N> constexpr auto qMakeStaticCaseSensitiveLatin1StringMatcher(const char
64 (&patternToMatch)[N])
65
66 \since 6.7
67 \relates QStaticLatin1StringMatcher
68
69 Return a QStaticLatin1StringMatcher with the correct \a N determined
70 automatically from the \a patternToMatch passed, and with case sensitivity.
71
72 To take full advantage of this function, assign the result to a
73 \c{static constexpr auto} variable:
74
75 \snippet code/src_corelib_text_qstaticlatin1stringmatcher.cpp 0
76*/
77
78/*!
79 \fn template<size_t N> constexpr auto qMakeStaticCaseInsensitiveLatin1StringMatcher(const char
80 (&patternToMatch)[N])
81
82 \since 6.7
83 \relates QStaticLatin1StringMatcher
84
85 Return a QStaticLatin1StringMatcher with the correct \a N determined
86 automatically from the \a patternToMatch passed, and without case sensitivity.
87
88 To take full advantage of this function, assign the result to a
89 \c{static constexpr auto} variable:
90
91 \snippet code/src_corelib_text_qstaticlatin1stringmatcher.cpp 1
92*/