QUtf8StringView Class
The QUtf8StringView class provides a unified view on UTF-8 strings with a read-only subset of the QString API. More…
| Header | #include <QUtf8StringView> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Core) |
| Module | Nt Core C++ Classes |
| Since | 6.0 |
List of all members, including inherited members
Public Types
| typedef | storage_type |
| typedef | value_type |
| typedef | const_iterator |
| typedef | iterator |
| typedef | size_type |
| typedef | const_reverse_iterator |
| typedef | reverse_iterator |
Public Functions
| QUtf8StringView() | |
| QUtf8StringView(std::nullptr_t) | |
| QUtf8StringView(const char *str, qsizetype len) | |
| QUtf8StringView(const char *str) | |
| QUtf8StringView(const QByteArray &ba) | |
| QUtf8StringView(std::string_view s) | |
| QUtf8StringView(const std::string &s) | |
| QString | toString() const |
| const char * | data() const |
| const char * | utf8() const |
| qsizetype | size() const |
| qsizetype | length() const |
| qsizetype | size_bytes() const |
| bool | isNull() const |
| bool | isEmpty() const |
| bool | empty() const |
| char | at(qsizetype i) const |
| char | operator[](qsizetype i) const |
| char | front() const |
| char | back() const |
| QUtf8StringView | first(qsizetype count) const |
| QUtf8StringView | last(qsizetype count) const |
| QUtf8StringView | sliced(qsizetype pos) const |
| QUtf8StringView | sliced(qsizetype pos, qsizetype count) const |
| QUtf8StringView | chopped(qsizetype count) const |
| QUtf8StringView | left(qsizetype count) const |
| QUtf8StringView | right(qsizetype count) const |
| QUtf8StringView | mid(qsizetype pos, qsizetype count = -1) const |
| QUtf8StringView & | slice(qsizetype pos) |
| QUtf8StringView & | slice(qsizetype pos, qsizetype count) |
| void | truncate(qsizetype count) |
| void | chop(qsizetype count) |
| bool | isValidUtf8() const |
| int | compare(QUtf8StringView other, Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| const_iterator | begin() const |
| const_iterator | end() const |
| const_iterator | cbegin() const |
| const_iterator | cend() const |
| const_reverse_iterator | rbegin() const |
| const_reverse_iterator | rend() const |
| const_reverse_iterator | crbegin() const |
| const_reverse_iterator | crend() const |
Static Public Members
Detailed Description
A QUtf8StringView refers to a range of UTF-8 bytes without owning or copying them, so the viewed data must outlive the view. Sizes and indexes count bytes (code units), not characters.
QUtf8StringView name = "Grüße";
qsizetype bytes = name.size(); // 7
QString text = name.toString(); // 5 characters
See also QStringView, QLatin1StringView and QAnyStringView.
Differences from Qt
QUtf8StringView is a class, not an alias of the QBasicUtf8StringView template, and there is no char8_t support because Nt is built as C++17. Comparisons compare the bytes, which orders the strings by code point.
Member Type Documentation
typedef QUtf8StringView::const_iterator
A random access iterator over the bytes of the view.
typedef QUtf8StringView::const_reverse_iterator
The reverse iterator type, for STL compatibility.
typedef QUtf8StringView::iterator
Same as const_iterator; the view is read-only.
typedef QUtf8StringView::reverse_iterator
Same as const_reverse_iterator; the view is read-only.
typedef QUtf8StringView::size_type
Alias for qsizetype.
typedef QUtf8StringView::storage_type
The type of a code unit, char.
typedef QUtf8StringView::value_type
Alias for const char.
Member Function Documentation
QUtf8StringView::QUtf8StringView()
Constructs a null view.
See also isNull().
QUtf8StringView::QUtf8StringView(std::nullptr_t)
Constructs a null view.
QUtf8StringView::QUtf8StringView(const char *str, qsizetype len)
Constructs a view of the len bytes at str.
QUtf8StringView::QUtf8StringView(const char *str)
Constructs a view of the null-terminated string str. A null str gives a null view.
QUtf8StringView::QUtf8StringView(const QByteArray &ba)
Constructs a view of the bytes of ba. A null byte array gives a null view.
QUtf8StringView::QUtf8StringView(std::string_view s)
Constructs a view of the bytes of s.
QUtf8StringView::QUtf8StringView(const std::string &s)
Constructs a view of the bytes of s.
char QUtf8StringView::at(qsizetype i) const
Returns the byte at index i, which must be valid.
char QUtf8StringView::back() const
Returns the last byte. The view must not be empty.
const_iterator QUtf8StringView::begin() const
Returns an iterator to the first byte.
const_iterator QUtf8StringView::cbegin() const
Same as begin().
const_iterator QUtf8StringView::cend() const
Same as end().
void QUtf8StringView::chop(qsizetype count)
Removes count bytes from the end of the view.
QUtf8StringView QUtf8StringView::chopped(qsizetype count) const
Returns a view without the last count bytes.
int QUtf8StringView::compare(QUtf8StringView other, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
Compares this view with other and returns a negative number, zero or a positive number if it is less than, equal to or greater than other. With Qt::CaseInsensitive (cs), the texts are compared after case folding.
This function was introduced in 6.5.
const_reverse_iterator QUtf8StringView::crbegin() const
Same as rbegin().
const_reverse_iterator QUtf8StringView::crend() const
Same as rend().
const char * QUtf8StringView::data() const
Returns a pointer to the first byte of the view. The data is not necessarily null-terminated.
bool QUtf8StringView::empty() const
Same as isEmpty(). Provided for STL compatibility.
const_iterator QUtf8StringView::end() const
Returns an iterator just past the last byte.
QUtf8StringView QUtf8StringView::first(qsizetype count) const
Returns a view of the first count bytes.
template <std::size_t Size> QUtf8StringView QUtf8StringView::fromArray(const char (&str)[Size])
Returns a view of the whole character array str, including a trailing '\0' if it has one.
char QUtf8StringView::front() const
Returns the first byte. The view must not be empty.
bool QUtf8StringView::isEmpty() const
Returns true if the view has no bytes; otherwise returns false.
bool QUtf8StringView::isNull() const
Returns true if the view is null; otherwise returns false.
bool QUtf8StringView::isValidUtf8() const
Returns true if the view holds well-formed UTF-8; otherwise returns false.
This function was introduced in 6.3.
QUtf8StringView QUtf8StringView::last(qsizetype count) const
Returns a view of the last count bytes.
QUtf8StringView QUtf8StringView::left(qsizetype count) const
Returns a view of the first count bytes, or the whole view if count is negative or larger than size().
See also first(), right() and mid().
qsizetype QUtf8StringView::length() const
Same as size().
qsizetype QUtf8StringView::max_size()
Returns the largest number of bytes a view can refer to.
This function was introduced in 6.8.
See also maxSize().
qsizetype QUtf8StringView::maxSize()
Returns the largest number of bytes a view can refer to.
This function was introduced in 6.8.
See also max_size().
QUtf8StringView QUtf8StringView::mid(qsizetype pos, qsizetype count = -1) const
Returns a view of count bytes from index pos, or of the bytes from pos to the end if count is negative or reaches past the end. Returns an empty view if pos is past the end.
See also sliced(), left() and right().
char QUtf8StringView::operator[](qsizetype i) const
Same as at(i).
const_reverse_iterator QUtf8StringView::rbegin() const
Returns a reverse iterator to the last byte.
const_reverse_iterator QUtf8StringView::rend() const
Returns a reverse iterator just before the first byte.
QUtf8StringView QUtf8StringView::right(qsizetype count) const
Returns a view of the last count bytes, or the whole view if count is negative or larger than size().
See also last(), left() and mid().
qsizetype QUtf8StringView::size() const
Returns the number of bytes in the view.
qsizetype QUtf8StringView::size_bytes() const
Returns the size of the view in bytes, which is size().
QUtf8StringView & QUtf8StringView::slice(qsizetype pos)
Removes the bytes before index pos from the view and returns a reference to it.
This function was introduced in 6.8.
See also sliced().
QUtf8StringView & QUtf8StringView::slice(qsizetype pos, qsizetype count)
This is an overloaded function.
Makes the view refer to count bytes from index pos and returns a reference to it.
This function was introduced in 6.8.
QUtf8StringView QUtf8StringView::sliced(qsizetype pos) const
Returns a view of the bytes from index pos to the end.
QUtf8StringView QUtf8StringView::sliced(qsizetype pos, qsizetype count) const
This is an overloaded function.
Returns a view of count bytes from index pos.
QString QUtf8StringView::toString() const
Returns the viewed text converted to a QString.
void QUtf8StringView::truncate(qsizetype count)
Shortens the view to count bytes.
const char * QUtf8StringView::utf8() const
Same as data().