|
constexpr | QLatin1String () noexcept |
|
constexpr | QLatin1String (const char *s) noexcept |
|
constexpr | QLatin1String (const char *f, const char *l) |
|
constexpr | QLatin1String (const char *s, qsizetype sz) noexcept |
|
| QLatin1String (const QByteArray &s) noexcept |
|
constexpr | QLatin1String (QByteArrayView s) noexcept |
|
QString | toString () const |
|
constexpr const char * | latin1 () const noexcept |
|
constexpr qsizetype | size () const noexcept |
|
constexpr const char * | data () const noexcept |
|
constexpr bool | isNull () const noexcept |
|
constexpr bool | isEmpty () const noexcept |
|
template<typename... Args> |
QString | arg (Args &&...args) const |
|
constexpr QLatin1Char | at (qsizetype i) const |
|
constexpr QLatin1Char | operator[] (qsizetype i) const |
|
constexpr QLatin1Char | front () const |
|
constexpr QLatin1Char | back () const |
|
int | compare (QStringView other, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept |
|
int | compare (QLatin1String other, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept |
|
constexpr int | compare (QChar c) const noexcept |
|
int | compare (QChar c, Qt::CaseSensitivity cs) const noexcept |
|
bool | startsWith (QStringView s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept |
|
bool | startsWith (QLatin1String s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept |
|
constexpr bool | startsWith (QChar c) const noexcept |
|
bool | startsWith (QChar c, Qt::CaseSensitivity cs) const noexcept |
|
bool | endsWith (QStringView s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept |
|
bool | endsWith (QLatin1String s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept |
|
constexpr bool | endsWith (QChar c) const noexcept |
|
bool | endsWith (QChar c, Qt::CaseSensitivity cs) const noexcept |
|
qsizetype | indexOf (QStringView s, qsizetype from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept |
|
qsizetype | indexOf (QLatin1String s, qsizetype from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept |
|
qsizetype | indexOf (QChar c, qsizetype from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept |
|
bool | contains (QStringView s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept |
|
bool | contains (QLatin1String s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept |
|
bool | contains (QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept |
|
qsizetype | lastIndexOf (QStringView s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept |
|
qsizetype | lastIndexOf (QStringView s, qsizetype from, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept |
|
qsizetype | lastIndexOf (QLatin1String s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept |
|
qsizetype | lastIndexOf (QLatin1String s, qsizetype from, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept |
|
qsizetype | lastIndexOf (QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept |
|
qsizetype | lastIndexOf (QChar c, qsizetype from, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept |
|
constexpr const_iterator | begin () const noexcept |
|
constexpr const_iterator | cbegin () const noexcept |
|
constexpr const_iterator | end () const noexcept |
|
constexpr const_iterator | cend () const noexcept |
|
const_reverse_iterator | rbegin () const noexcept |
|
const_reverse_iterator | crbegin () const noexcept |
|
const_reverse_iterator | rend () const noexcept |
|
const_reverse_iterator | crend () const noexcept |
|
constexpr QLatin1String | mid (qsizetype pos, qsizetype n=-1) const |
|
constexpr QLatin1String | left (qsizetype n) const |
|
constexpr QLatin1String | right (qsizetype n) const |
|
constexpr QLatin1String | sliced (qsizetype pos) const |
|
constexpr QLatin1String | sliced (qsizetype pos, qsizetype n) const |
|
constexpr QLatin1String | first (qsizetype n) const |
|
constexpr QLatin1String | last (qsizetype n) const |
|
constexpr QLatin1String | chopped (qsizetype n) const |
|
constexpr void | chop (qsizetype n) |
|
constexpr void | truncate (qsizetype n) |
|
QLatin1String | trimmed () const noexcept |
|
template<typename Needle , typename... Flags> |
constexpr auto | tokenize (Needle &&needle, Flags...flags) const noexcept(noexcept(qTokenize(std::declval< const QLatin1String & >(), std::forward< Needle >(needle), flags...))) -> decltype(qTokenize(*this, std::forward< Needle >(needle), flags...)) |
|
QT_ASCII_CAST_WARN bool | operator== (const char *s) const |
|
QT_ASCII_CAST_WARN bool | operator!= (const char *s) const |
|
QT_ASCII_CAST_WARN bool | operator< (const char *s) const |
|
QT_ASCII_CAST_WARN bool | operator> (const char *s) const |
|
QT_ASCII_CAST_WARN bool | operator<= (const char *s) const |
|
QT_ASCII_CAST_WARN bool | operator>= (const char *s) const |
|
QT_ASCII_CAST_WARN bool | operator== (const QByteArray &s) const |
|
QT_ASCII_CAST_WARN bool | operator!= (const QByteArray &s) const |
|
QT_ASCII_CAST_WARN bool | operator< (const QByteArray &s) const |
|
QT_ASCII_CAST_WARN bool | operator> (const QByteArray &s) const |
|
QT_ASCII_CAST_WARN bool | operator<= (const QByteArray &s) const |
|
QT_ASCII_CAST_WARN bool | operator>= (const QByteArray &s) const |
|
template<typename... Args> |
Q_ALWAYS_INLINE QString | arg (Args &&...args) const |
|
|
bool | operator== (QLatin1String s1, QLatin1String s2) noexcept |
|
bool | operator!= (QLatin1String s1, QLatin1String s2) noexcept |
|
bool | operator< (QLatin1String s1, QLatin1String s2) noexcept |
|
bool | operator> (QLatin1String s1, QLatin1String s2) noexcept |
|
bool | operator<= (QLatin1String s1, QLatin1String s2) noexcept |
|
bool | operator>= (QLatin1String s1, QLatin1String s2) noexcept |
|
bool | operator== (QChar lhs, QLatin1String rhs) noexcept |
|
bool | operator< (QChar lhs, QLatin1String rhs) noexcept |
|
bool | operator> (QChar lhs, QLatin1String rhs) noexcept |
|
bool | operator!= (QChar lhs, QLatin1String rhs) noexcept |
|
bool | operator<= (QChar lhs, QLatin1String rhs) noexcept |
|
bool | operator>= (QChar lhs, QLatin1String rhs) noexcept |
|
bool | operator== (QLatin1String lhs, QChar rhs) noexcept |
|
bool | operator!= (QLatin1String lhs, QChar rhs) noexcept |
|
bool | operator< (QLatin1String lhs, QChar rhs) noexcept |
|
bool | operator> (QLatin1String lhs, QChar rhs) noexcept |
|
bool | operator<= (QLatin1String lhs, QChar rhs) noexcept |
|
bool | operator>= (QLatin1String lhs, QChar rhs) noexcept |
|
bool | operator== (QStringView lhs, QLatin1String rhs) noexcept |
|
bool | operator!= (QStringView lhs, QLatin1String rhs) noexcept |
|
bool | operator< (QStringView lhs, QLatin1String rhs) noexcept |
|
bool | operator<= (QStringView lhs, QLatin1String rhs) noexcept |
|
bool | operator> (QStringView lhs, QLatin1String rhs) noexcept |
|
bool | operator>= (QStringView lhs, QLatin1String rhs) noexcept |
|
bool | operator== (QLatin1String lhs, QStringView rhs) noexcept |
|
bool | operator!= (QLatin1String lhs, QStringView rhs) noexcept |
|
bool | operator< (QLatin1String lhs, QStringView rhs) noexcept |
|
bool | operator<= (QLatin1String lhs, QStringView rhs) noexcept |
|
bool | operator> (QLatin1String lhs, QStringView rhs) noexcept |
|
bool | operator>= (QLatin1String lhs, QStringView rhs) noexcept |
|
QT_ASCII_CAST_WARN friend bool | operator== (const char *s1, QLatin1String s2) |
|
QT_ASCII_CAST_WARN friend bool | operator!= (const char *s1, QLatin1String s2) |
|
QT_ASCII_CAST_WARN friend bool | operator< (const char *s1, QLatin1String s2) |
|
QT_ASCII_CAST_WARN friend bool | operator> (const char *s1, QLatin1String s2) |
|
QT_ASCII_CAST_WARN friend bool | operator<= (const char *s1, QLatin1String s2) |
|
QT_ASCII_CAST_WARN friend bool | operator>= (const char *s1, QLatin1String s2) |
|
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal.
\inmodule QtCore
\reentrant
Many of QString's member functions are overloaded to accept
{const char *} instead of QString. This includes the copy constructor, the assignment operator, the comparison operators, and various other functions such as \l{QString::insert()}{insert()}, \l{QString::replace()}{replace()}, and \l{QString::indexOf()}{indexOf()}. These functions are usually optimized to avoid constructing a QString object for the
{const char *} data. For example, assuming str
is a QString,
is much faster than
because it doesn't construct four temporary QString objects and make a deep copy of the character data.
Applications that define \l QT_NO_CAST_FROM_ASCII (as explained in the QString documentation) don't have access to QString's
{const char *} API. To provide an efficient way of specifying constant Latin-1 strings, Qt provides the QLatin1String, which is just a very thin wrapper around a
{const char *}. Using QLatin1String, the example code above becomes
This is a bit longer to type, but it provides exactly the same benefits as the first version of the code, and is faster than converting the Latin-1 strings using QString::fromLatin1().
Thanks to the QString(QLatin1String) constructor, QLatin1String can be used everywhere a QString is expected. For example:
- Note
- If the function you're calling with a QLatin1String argument isn't actually overloaded to take QLatin1String, the implicit conversion to QString will trigger a memory allocation, which is usually what you want to avoid by using QLatin1String in the first place. In those cases, using QStringLiteral may be the better option.
- See also
- QString, QLatin1Char, {QStringLiteral()}{QStringLiteral}, QT_NO_CAST_FROM_ASCII
Definition at line 83 of file qstring.h.
QLatin1String::QLatin1String |
( |
const char * |
first, |
|
|
const char * |
last |
|
) |
| |
|
inlineexplicitconstexpr |
- Since
- 5.10
Constructs a QLatin1String object that stores first with length (last - first).
The range
{[first,last)} must remain valid for the lifetime of this Latin-1 string object.
Passing \nullptr as first is safe if last is \nullptr, too, and results in a null Latin-1 string.
The behavior is undefined if last precedes first, first is \nullptr and last is not, or if
{last - first > INT_MAX}.
Definition at line 88 of file qstring.h.
- Since
- 5.14
Returns the index position of the first occurrence of the string-view str, Latin-1 string l1, or character ch, respectively, in this Latin-1 string, searching forward from index position from. Returns -1 if str is not found.
If cs is Qt::CaseSensitive (default), the search is case sensitive; otherwise the search is case insensitive.
If from is -1, the search starts at the last character; if it is -2, at the next to last character and so on.
- See also
- QString::indexOf()
Definition at line 144 of file qstring.h.
- Since
- 5.14
Returns the index position of the last occurrence of the string-view str, Latin-1 string l1, or character ch, respectively, in this Latin-1 string, searching backward from index position from. Returns -1 if str is not found.
If from is -1, the search starts at the last character; if from is -2, at the next to last character and so on.
If cs is Qt::CaseSensitive (default), the search is case sensitive; otherwise the search is case insensitive.
- Note
- When searching for a 0-length str or l1, the match at the end of the data is excluded from the search by a negative from, even though
{-1} is normally thought of as searching from the end of the string: the match at the end is after the last character, so it is excluded. To include such a final empty match, either give a positive value for from or omit the from parameter entirely.
- See also
- indexOf(), QStringView::lastIndexOf(), QStringView::indexOf(), QString::indexOf()
Definition at line 164 of file qstring.h.
- Since
- 5.8
Returns the substring of length length starting at position start in this Latin-1 string.
If you know that start and length cannot be out of bounds, use sliced() instead in new code, because it is faster.
Returns an empty Latin-1 string if start exceeds the length of this Latin-1 string. If there are less than length characters available in this Latin-1 string starting at start, or if length is negative (default), the function returns all characters that are available from start.
- See also
- first(), last(), sliced(), chopped(), chop(), truncate()
Definition at line 188 of file qstring.h.