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