QLatin1StringView Class
The QLatin1StringView class provides a thin wrapper around a US-ASCII/Latin-1 encoded string literal. More…
| Header | #include <QLatin1StringView> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Core) |
| Module | Nt Core C++ Classes |
List of all members, including inherited members
Public Types
| typedef | const_iterator |
| typedef | const_reverse_iterator |
| typedef | reverse_iterator |
Public Functions
| QLatin1StringView() | |
| QLatin1StringView(const char *s) | |
| QLatin1StringView(const char *s, qsizetype len) | |
| QLatin1StringView(const QByteArray &b) | |
| const char * | latin1() const |
| const char * | data() const |
| qsizetype | size() const |
| bool | isEmpty() const |
| QChar | at(qsizetype i) const |
| QChar | operator[](qsizetype i) const |
| qsizetype | length() const |
| bool | empty() const |
| QChar | front() const |
| QChar | back() const |
| QLatin1StringView | first(qsizetype len) const |
| QLatin1StringView | last(qsizetype len) const |
| QLatin1StringView | sliced(qsizetype pos) const |
| QLatin1StringView | sliced(qsizetype pos, qsizetype len) const |
| QLatin1StringView | chopped(qsizetype len) const |
| void | chop(qsizetype len) |
| void | truncate(qsizetype len) |
| QLatin1StringView | mid(qsizetype pos, qsizetype len = -1) const |
| QLatin1StringView | left(qsizetype len) const |
| QLatin1StringView | right(qsizetype len) const |
| QLatin1StringView | trimmed() const |
| const char * | begin() const |
| const char * | end() const |
| const char * | cbegin() const |
| const char * | cend() const |
| QLatin1StringView(const char *first, End last) | |
| QLatin1StringView(QByteArrayView b) | |
| bool | isNull() const |
| const_reverse_iterator | rbegin() const |
| const_reverse_iterator | rend() const |
| const_reverse_iterator | crbegin() const |
| const_reverse_iterator | crend() const |
| const_iterator | constBegin() const |
| const_iterator | constEnd() const |
| const char * | constData() const |
| QLatin1StringView & | slice(qsizetype pos) |
| QLatin1StringView & | slice(qsizetype pos, qsizetype len) |
| short | toShort(bool *ok = nullptr, int base = 10) const |
| ushort | toUShort(bool *ok = nullptr, int base = 10) const |
| int | toInt(bool *ok = nullptr, int base = 10) const |
| uint | toUInt(bool *ok = nullptr, int base = 10) const |
| long | toLong(bool *ok = nullptr, int base = 10) const |
| ulong | toULong(bool *ok = nullptr, int base = 10) const |
| qlonglong | toLongLong(bool *ok = nullptr, int base = 10) const |
| qulonglong | toULongLong(bool *ok = nullptr, int base = 10) const |
| float | toFloat(bool *ok = nullptr) const |
| double | toDouble(bool *ok = nullptr) const |
| QString | arg(const A &a, const Rest &...rest) const |
| QString | toString() const |
| bool | startsWith(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| bool | startsWith(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| bool | endsWith(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| bool | endsWith(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| qsizetype | indexOf(const QString &s, qsizetype from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| qsizetype | indexOf(QChar c, qsizetype from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| qsizetype | lastIndexOf(const QString &s, qsizetype from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| qsizetype | lastIndexOf(QChar c, qsizetype from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| bool | contains(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| bool | contains(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| qsizetype | count(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| qsizetype | count(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| int | compare(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
Static Public Members
Detailed Description
A QLatin1StringView refers to a sequence of Latin-1 bytes without owning or copying them, so the viewed memory must outlive it. It is mainly used to pass 8-bit literals to QString functions without an intermediate conversion. QLatin1String is an alias for this class.
See also QString and QLatin1Char.
Differences from Qt
The searching and comparison functions that take a QString convert the view to a QString first, so they allocate, and so do the number conversions. arg() takes strings and characters only. first(), last(), sliced(), chopped(), slice(), truncate() and chop() do not check their arguments.
Member Type Documentation
typedef QLatin1StringView::const_iterator
A read-only iterator over the characters of the view. It is a plain const char *.
typedef QLatin1StringView::const_reverse_iterator
A read-only reverse iterator over the characters of the view.
typedef QLatin1StringView::reverse_iterator
The reverse iterator type, for STL compatibility. It is the same as const_reverse_iterator.
Member Function Documentation
QLatin1StringView::QLatin1StringView()
Constructs an empty Latin-1 string view.
QLatin1StringView::QLatin1StringView(const char *s)
Constructs a view of the null-terminated string s. The length is determined by scanning for the terminator; a null s gives an empty view.
QLatin1StringView::QLatin1StringView(const char *s, qsizetype len)
This is an overloaded function.
Constructs a view of the first len bytes of s.
QLatin1StringView::QLatin1StringView(const QByteArray &b)
This is an overloaded function.
Constructs a view of the contents of the byte array b.
template <typename End, typename = std::enable_if_t<std::is_pointer_v<End> && std::is_convertible_v<End, const char *>>> QLatin1StringView::QLatin1StringView(const char *first, End last)
This is an overloaded function.
Constructs a view of the characters from first up to, but not including, last. last must be a pointer, so that a literal 0 as the second argument still means a length.
QLatin1StringView::QLatin1StringView(QByteArrayView b)
This is an overloaded function.
Constructs a view of the bytes of b, read as Latin-1. The view is null if b is null.
template <typename A, typename... Rest>QString QLatin1StringView::arg(const A &a, const Rest &...rest) const
Returns a string in which the place markers of this view (%1 to %99) are replaced by a and rest: the lowest-numbered marker by a, the next one by the first of rest, and so on. The arguments are strings, views or characters. The markers are replaced in one pass, so a marker inside an argument is left alone.
See also QString::arg().
QChar QLatin1StringView::at(qsizetype i) const
Returns the character at index position i as a QChar. i must be a valid index; no bounds checking is done.
QChar QLatin1StringView::back() const
Returns the last character. The view must not be empty.
This function was introduced in 5.10.
const char * QLatin1StringView::begin() const
Returns a pointer to the first byte, for iteration.
This function was introduced in 5.10.
const char * QLatin1StringView::cbegin() const
Returns a pointer to the first byte. Same as begin().
This function was introduced in 5.10.
const char * QLatin1StringView::cend() const
Returns a pointer just past the last byte. Same as end().
This function was introduced in 5.10.
void QLatin1StringView::chop(qsizetype len)
Removes len characters from the end of the view.
This function was introduced in 5.10.
QLatin1StringView QLatin1StringView::chopped(qsizetype len) const
Returns a view without the last len characters.
This function was introduced in 5.10.
int QLatin1StringView::compare(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
Compares the view with s, using cs, and returns a negative number, zero or a positive number as the view sorts before, equal to or after it.
const_iterator QLatin1StringView::constBegin() const
Returns a const iterator pointing to the first character of the view. This is the same as begin().
const char * QLatin1StringView::constData() const
Returns a pointer to the Latin-1 characters of the view. This is the same as data().
const_iterator QLatin1StringView::constEnd() const
Returns a const iterator pointing just after the last character of the view. This is the same as end().
bool QLatin1StringView::contains(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
Returns true if the view contains s, compared with cs.
bool QLatin1StringView::contains(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
This is an overloaded function.
Returns true if the view contains c, compared with cs.
qsizetype QLatin1StringView::count(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
Returns how often s occurs, possibly overlapping, compared with cs.
qsizetype QLatin1StringView::count(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
This is an overloaded function.
Returns how often c occurs, compared with cs.
const_reverse_iterator QLatin1StringView::crbegin() const
Returns a reverse iterator pointing to the last character of the view. This is the same as rbegin().
const_reverse_iterator QLatin1StringView::crend() const
Returns a reverse iterator pointing just before the first character of the view. This is the same as rend().
const char * QLatin1StringView::data() const
Returns a pointer to the first byte of the viewed string. The data is not necessarily null-terminated.
bool QLatin1StringView::empty() const
Returns true if the view is empty. Provided for STL compatibility.
This function was introduced in 6.0.
const char * QLatin1StringView::end() const
Returns a pointer just past the last byte.
This function was introduced in 5.10.
bool QLatin1StringView::endsWith(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
Returns true if the view ends with s, compared with cs.
bool QLatin1StringView::endsWith(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
This is an overloaded function.
Returns true if the view ends with c, compared with cs.
QLatin1StringView QLatin1StringView::first(qsizetype len) const
Returns a view of the first len characters.
This function was introduced in 6.0.
QChar QLatin1StringView::front() const
Returns the first character. The view must not be empty.
This function was introduced in 5.10.
qsizetype QLatin1StringView::indexOf(const QString &s, qsizetype from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
Returns the position of the first s at or after from, compared with cs, or -1.
qsizetype QLatin1StringView::indexOf(QChar c, qsizetype from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
This is an overloaded function.
Returns the position of the first c at or after from, compared with cs, or -1.
bool QLatin1StringView::isEmpty() const
Returns true if the view has no characters; otherwise returns false.
See also size().
bool QLatin1StringView::isNull() const
Returns true if the view has no data, as a default-constructed one; otherwise returns false. A null view is also empty.
See also isEmpty().
QLatin1StringView QLatin1StringView::last(qsizetype len) const
Returns a view of the last len characters.
This function was introduced in 6.0.
See also first() and sliced().
qsizetype QLatin1StringView::lastIndexOf(const QString &s, qsizetype from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
Returns the position of the last s at or before from (-1 means the end), compared with cs, or -1.
qsizetype QLatin1StringView::lastIndexOf(QChar c, qsizetype from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
This is an overloaded function.
Returns the position of the last c at or before from, compared with cs, or -1.
const char * QLatin1StringView::latin1() const
Returns a pointer to the first byte of the viewed string.
See also data().
QLatin1StringView QLatin1StringView::left(qsizetype len) const
Returns a view of the first len characters, or the whole view.
This function was introduced in 5.8.
qsizetype QLatin1StringView::length() const
Returns the number of characters, the same as size().
This function was introduced in 6.0.
qsizetype QLatin1StringView::max_size()
Returns the largest number of characters a view can refer to.
This function was introduced in 6.8.
qsizetype QLatin1StringView::maxSize()
Returns the largest number of characters a view can refer to. This is the same as max_size().
This function was introduced in 6.8.
QLatin1StringView QLatin1StringView::mid(qsizetype pos, qsizetype len = -1) const
Returns a view of len characters starting at pos, or up to the end if len is negative. Positions outside the view are clamped.
This function was introduced in 5.8.
QChar QLatin1StringView::operator[](qsizetype i) const
Returns the character at index position i. This is the same as at().
const_reverse_iterator QLatin1StringView::rbegin() const
Returns a reverse iterator pointing to the last character of the view.
See also rend().
const_reverse_iterator QLatin1StringView::rend() const
Returns a reverse iterator pointing just before the first character of the view.
See also rbegin().
QLatin1StringView QLatin1StringView::right(qsizetype len) const
Returns a view of the last len characters, or the whole view.
This function was introduced in 5.8.
qsizetype QLatin1StringView::size() const
Returns the number of bytes in the view.
See also isEmpty().
QLatin1StringView & QLatin1StringView::slice(qsizetype pos)
Changes the view to start at index position pos and to extend to its end, and returns a reference to it. pos must not exceed size().
This function was introduced in 6.8.
See also sliced().
QLatin1StringView & QLatin1StringView::slice(qsizetype pos, qsizetype len)
This is an overloaded function.
Changes the view to the len characters that start at index position pos, and returns a reference to it. The range must lie within the view.
This function was introduced in 6.8.
QLatin1StringView QLatin1StringView::sliced(qsizetype pos) const
Returns a view of the characters from pos to the end.
This function was introduced in 6.0.
QLatin1StringView QLatin1StringView::sliced(qsizetype pos, qsizetype len) const
This is an overloaded function.
Returns a view of len characters starting at pos.
This function was introduced in 6.0.
bool QLatin1StringView::startsWith(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
Returns true if the view starts with s, compared with cs.
bool QLatin1StringView::startsWith(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
This is an overloaded function.
Returns true if the view starts with c, compared with cs.
double QLatin1StringView::toDouble(bool *ok = nullptr) const
Returns the view converted to a double, or 0 if it is not a number, and sets *ok if ok is not nullptr. The text is read in the C locale.
This function was introduced in 6.4.
float QLatin1StringView::toFloat(bool *ok = nullptr) const
Returns the view converted to a float, or 0 if it is not a number, and sets *ok if ok is not nullptr.
This function was introduced in 6.4.
int QLatin1StringView::toInt(bool *ok = nullptr, int base = 10) const
Returns the view converted to an int in base base, as QString::toInt() does, and sets *ok if ok is not nullptr.
This function was introduced in 6.4.
long QLatin1StringView::toLong(bool *ok = nullptr, int base = 10) const
Returns the view converted to a long in base base, and sets *ok if ok is not nullptr.
This function was introduced in 6.4.
qlonglong QLatin1StringView::toLongLong(bool *ok = nullptr, int base = 10) const
Returns the view converted to a long long in base base, and sets *ok if ok is not nullptr.
This function was introduced in 6.4.
short QLatin1StringView::toShort(bool *ok = nullptr, int base = 10) const
Returns the view converted to a short in base base, as QString::toShort() does. Returns 0 if the conversion fails; if ok is not nullptr, *ok is set to whether it succeeded.
This function was introduced in 6.4.
QString QLatin1StringView::toString() const
Returns the view as a QString.
uint QLatin1StringView::toUInt(bool *ok = nullptr, int base = 10) const
Returns the view converted to an unsigned int in base base, and sets *ok if ok is not nullptr.
This function was introduced in 6.4.
ulong QLatin1StringView::toULong(bool *ok = nullptr, int base = 10) const
Returns the view converted to an unsigned long in base base, and sets *ok if ok is not nullptr.
This function was introduced in 6.4.
qulonglong QLatin1StringView::toULongLong(bool *ok = nullptr, int base = 10) const
Returns the view converted to an unsigned long long in base base, and sets *ok if ok is not nullptr.
This function was introduced in 6.4.
ushort QLatin1StringView::toUShort(bool *ok = nullptr, int base = 10) const
Returns the view converted to an unsigned short in base base, and sets *ok if ok is not nullptr.
This function was introduced in 6.4.
QLatin1StringView QLatin1StringView::trimmed() const
Returns a view without the leading and trailing white space (space, tab, line feed, vertical tab, form feed, carriage return, U+0085 and U+00A0).
This function was introduced in 5.10.
void QLatin1StringView::truncate(qsizetype len)
Shortens the view to len characters.
This function was introduced in 5.10.