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
This class is useful when your code needs to search efficiently
15
in Latin-1 strings for a substring that's known at compile-time.
16
This is common, for example, in parsers. Using a matcher
17
object's indexIn() is faster than using the indexOf() member method of
18
the string you are searching in, especially when the string to
19
be found will be searched for repeatedly or within a large
20
Latin-1 string that may contain many matches to prefixes of the
21
substring to be found.
22
23
Unlike QLatin1StringMatcher, this class calculates the internal
24
representation at \e{compile-time}, so it can be beneficial even if you
25
are doing one-off Latin-1 string matches.
26
27
Create the QStaticLatin1StringMatcher by calling
28
qMakeStaticCaseSensitiveLatin1StringMatcher() or
29
qMakeStaticCaseInsensitiveLatin1StringMatcher() passing the Latin-1
30
string to search for as a C string literal. Store the return value of
31
that function in a \c{static constexpr auto} variable, so you don't
32
need to pass the \c{N} template parameter explicitly.
33
34
Then call indexIn() on the QLatin1StringView in which you want to search,
35
just like with QLatin1StringMatcher.
36
37
Since this class is designed to do all the up-front calculations at
38
compile-time, it does not offer setPattern() or setCaseSensitivity()
39
methods.
40
41
\note INTEGRITY operating system is currently not supported.
42
43
\sa QLatin1StringMatcher, QStaticByteArrayMatcher, QByteArrayMatcher
44
*/
45
46
/*!
47
\fn template<Qt::CaseSensitivity CS, size_t N> constexpr qsizetype QStaticLatin1StringMatcher<CS, N>::indexIn(QLatin1StringView haystack, qsizetype from) const
48
\fn template<Qt::CaseSensitivity CS, size_t N> constexpr qsizetype QStaticLatin1StringMatcher<CS, N>::indexIn(QStringView haystack, qsizetype from) const
49
50
Searches the QLatin1StringView \a haystack, from byte position \a from
51
(default 0, i.e. from the first byte), for QLatin1StringView pattern()
52
that was set in the constructor. Using the case sensitivity that was also
53
set in the constructor.
54
55
Returns the position where the pattern() matched in \a haystack, or -1 if no match was found.
56
*/
57
58
/*!
59
\fn template<size_t N> constexpr auto qMakeStaticCaseSensitiveLatin1StringMatcher(const char
60
(&patternToMatch)[N])
61
62
\since 6.7
63
\relates QStaticLatin1StringMatcher
64
65
Return a QStaticLatin1StringMatcher with the correct \c{N} determined
66
automatically from the \a patternToMatch passed, and with case sensitivity.
67
68
To take full advantage of this function, assign the result to a
69
\c{static constexpr auto} variable:
70
71
\snippet code/src_corelib_text_qstaticlatin1stringmatcher.cpp 0
72
*/
73
74
/*!
75
\fn template<size_t N> constexpr auto qMakeStaticCaseInsensitiveLatin1StringMatcher(const char
76
(&patternToMatch)[N])
77
78
\since 6.7
79
\relates QStaticLatin1StringMatcher
80
81
Return a QStaticLatin1StringMatcher with the correct \c{N} determined
82
automatically from the \a patternToMatch passed, and without case sensitivity.
83
84
To take full advantage of this function, assign the result to a
85
\c{static constexpr auto} variable:
86
87
\snippet code/src_corelib_text_qstaticlatin1stringmatcher.cpp 1
88
*/
qtbase
src
corelib
text
qstaticlatin1stringmatcher.qdoc
Generated on
for Qt by
1.14.0