6.0.0-rc4Source

QLatin1StringView Class

The QLatin1StringView class provides a thin wrapper around a US-ASCII/Latin-1 encoded string literal. More…

Header#include <QLatin1StringView>
CMaketarget_link_libraries(app PRIVATE Nt::Core)
ModuleNt Core C++ Classes

List of all members, including inherited members

Public Types

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
qsizetypesize() const
boolisEmpty() const
QCharat(qsizetype i) const
QCharoperator[](qsizetype i) const
qsizetypelength() const
boolempty() const
QCharfront() const
QCharback() const
QLatin1StringViewfirst(qsizetype len) const
QLatin1StringViewlast(qsizetype len) const
QLatin1StringViewsliced(qsizetype pos) const
QLatin1StringViewsliced(qsizetype pos, qsizetype len) const
QLatin1StringViewchopped(qsizetype len) const
voidchop(qsizetype len)
voidtruncate(qsizetype len)
QLatin1StringViewmid(qsizetype pos, qsizetype len = -1) const
QLatin1StringViewleft(qsizetype len) const
QLatin1StringViewright(qsizetype len) const
QLatin1StringViewtrimmed() 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)
boolisNull() const
const_reverse_iteratorrbegin() const
const_reverse_iteratorrend() const
const_reverse_iteratorcrbegin() const
const_reverse_iteratorcrend() const
const_iteratorconstBegin() const
const_iteratorconstEnd() const
const char *constData() const
QLatin1StringView &slice(qsizetype pos)
QLatin1StringView &slice(qsizetype pos, qsizetype len)
shorttoShort(bool *ok = nullptr, int base = 10) const
ushorttoUShort(bool *ok = nullptr, int base = 10) const
inttoInt(bool *ok = nullptr, int base = 10) const
uinttoUInt(bool *ok = nullptr, int base = 10) const
longtoLong(bool *ok = nullptr, int base = 10) const
ulongtoULong(bool *ok = nullptr, int base = 10) const
qlonglongtoLongLong(bool *ok = nullptr, int base = 10) const
qulonglongtoULongLong(bool *ok = nullptr, int base = 10) const
floattoFloat(bool *ok = nullptr) const
doubletoDouble(bool *ok = nullptr) const
QStringarg(const A &a, const Rest &...rest) const
QStringtoString() const
boolstartsWith(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
boolstartsWith(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
boolendsWith(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
boolendsWith(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
qsizetypeindexOf(const QString &s, qsizetype from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
qsizetypeindexOf(QChar c, qsizetype from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
qsizetypelastIndexOf(const QString &s, qsizetype from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
qsizetypelastIndexOf(QChar c, qsizetype from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
boolcontains(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
boolcontains(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
qsizetypecount(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
qsizetypecount(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
intcompare(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const

Static Public Members

qsizetypemax_size()
qsizetypemaxSize()

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

[constexpr] QLatin1StringView::QLatin1StringView()

Constructs an empty Latin-1 string view.

[constexpr] 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.

[constexpr] 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 *>>>[constexpr] 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.

[explicit] 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().

[constexpr] 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.

[constexpr] QChar QLatin1StringView::back() const

Returns the last character. The view must not be empty.

This function was introduced in 5.10.

[constexpr] const char * QLatin1StringView::begin() const

Returns a pointer to the first byte, for iteration.

This function was introduced in 5.10.

[constexpr] const char * QLatin1StringView::cbegin() const

Returns a pointer to the first byte. Same as begin().

This function was introduced in 5.10.

[constexpr] const char * QLatin1StringView::cend() const

Returns a pointer just past the last byte. Same as end().

This function was introduced in 5.10.

[constexpr] void QLatin1StringView::chop(qsizetype len)

Removes len characters from the end of the view.

This function was introduced in 5.10.

[constexpr] 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.

[constexpr] const_iterator QLatin1StringView::constBegin() const

Returns a const iterator pointing to the first character of the view. This is the same as begin().

[constexpr] const char * QLatin1StringView::constData() const

Returns a pointer to the Latin-1 characters of the view. This is the same as data().

[constexpr] 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().

[constexpr] const char * QLatin1StringView::data() const

Returns a pointer to the first byte of the viewed string. The data is not necessarily null-terminated.

See also latin1() and size().

[constexpr] bool QLatin1StringView::empty() const

Returns true if the view is empty. Provided for STL compatibility.

This function was introduced in 6.0.

[constexpr] 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.

[constexpr] QLatin1StringView QLatin1StringView::first(qsizetype len) const

Returns a view of the first len characters.

This function was introduced in 6.0.

See also last() and sliced().

[constexpr] 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.

[constexpr] bool QLatin1StringView::isEmpty() const

Returns true if the view has no characters; otherwise returns false.

See also size().

[constexpr] 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().

[constexpr] 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.

[constexpr] const char * QLatin1StringView::latin1() const

Returns a pointer to the first byte of the viewed string.

See also data().

[constexpr] 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.

[constexpr] qsizetype QLatin1StringView::length() const

Returns the number of characters, the same as size().

This function was introduced in 6.0.

[static, constexpr] qsizetype QLatin1StringView::max_size()

Returns the largest number of characters a view can refer to.

This function was introduced in 6.8.

[static, constexpr] 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.

[constexpr] 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.

[constexpr] 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().

Returns a view of the last len characters, or the whole view.

This function was introduced in 5.8.

[constexpr] qsizetype QLatin1StringView::size() const

Returns the number of bytes in the view.

See also isEmpty().

[constexpr] 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().

[constexpr] 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.

[constexpr] QLatin1StringView QLatin1StringView::sliced(qsizetype pos) const

Returns a view of the characters from pos to the end.

This function was introduced in 6.0.

See also first() and last().

[constexpr] 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.

[constexpr] 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.

[constexpr] void QLatin1StringView::truncate(qsizetype len)

Shortens the view to len characters.

This function was introduced in 5.10.