CopperSpice API  1.9.1
QString16 Class Reference

Provides a UTF-16 string class. More...

Inherits CsString_utf16

Classes

class  const_iterator
 STL style const iterator for QString16 More...
 
class  iterator
 STL style iterator for QString16 More...
 

Public Typedefs

using const_reverse_iterator = CsString::CsStringReverseIterator< const_iterator >
 
using difference_type = std::ptrdiff_t
 
using reverse_iterator = CsString::CsStringReverseIterator< iterator >
 
using size_type = std::ptrdiff_t
 
using storage_type = char16_t
 
using value_type = QChar32
 

Public Types

enum  NormalizationForm
 

Public Methods

 QString16 () = default
 
template<int N>
 QString16 (const char (&cStr)[N])
 
 QString16 (const char16_t *data)
 
 QString16 (const QByteArray &str)
 
 QString16 (const QChar32 *data, size_type numOfChars=-1)
 
 QString16 (const QString16 &other) = default
 
 QString16 (const_iterator begin, const_iterator end)
 
template<typename Iterator >
 QString16 (Iterator begin, Iterator end)
 
 QString16 (QChar32 c)
 
 QString16 (QChar32::SpecialCharacter c)
 
 QString16 (QString16 &&other) = default
 
 QString16 (QStringView16 str)
 
 QString16 (size_type numOfChars, QChar32 c)
 
 ~QString16 () = default
 
QString16 & append (char32_t c)
 
QString16 & append (const QChar32 *data, size_type numOfChars)
 
QString16 & append (const QString16 &other)
 
QString16 & append (const_iterator iter_begin, const_iterator iter_end)
 
QString16 & append (QChar32 c)
 
QString16 & append (QStringView16 str)
 
QString16 & append (QStringView16 str, size_type indexStart, size_type numOfChars)
 
QChar32 at (size_type index) const
 
QChar32 back () const
 
iterator begin ()
 
const_iterator begin () const
 
const_iterator cbegin () const
 
const_iterator cend () const
 
void chop (size_type numOfChars)
 
void clear ()
 
int compare (const QString16 &str, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
 
int compare (QStringView16 str, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
 
const_iterator constBegin () const
 
const char16_t * constData () const
 
const_iterator constEnd () const
 
bool contains (char ch, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
 
bool contains (const QRegularExpression16 &regExp) const
 
bool contains (const QString16 &str, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
 
bool contains (QChar32 c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
 
bool contains (QStringView16 str, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
 
size_type count () const
 
size_type count (const QRegularExpression16 &regExp) const
 
size_type count (const QString16 &str, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
 
size_type count (QChar32 c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
 
size_type count (QStringView16 str, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
 
const_reverse_iterator crbegin () const
 
const_reverse_iterator crend () const
 
const char16_t * data () const
 
bool empty () const
 
iterator end ()
 
const_iterator end () const
 
bool endsWith (const QString16 &str, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
 
bool endsWith (QChar32 c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
 
bool endsWith (QStringView16 str, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
 
QString16 & fill (QChar32 c, size_type numOfChars=-1)
 
QChar32 first () const
 
template<typename SP = QStringParser, typename... Ts>
QString16 formatArg (Ts &&...args) const
 
template<typename SP = QStringParser, typename... Ts>
QString16 formatArgs (Ts &&...args) const
 
QChar32 front () const
 
size_type indexOf (const QRegularExpression16 &regExp, size_type from=0) const
 
size_type indexOf (const QString16 &str, size_type from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
 
size_type indexOf (QChar32 c, size_type from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
 
const_iterator indexOfFast (const QRegularExpression16 &regExp) const
 
const_iterator indexOfFast (const QRegularExpression16 &regExp, const_iterator from) const
 
const_iterator indexOfFast (const QString16 &str) const
 
const_iterator indexOfFast (const QString16 &str, const_iterator from, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
 
const_iterator indexOfFast (QChar32 c) const
 
const_iterator indexOfFast (QChar32 c, const_iterator from, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
 
const_iterator indexOfFast (QStringView16 str, const_iterator from, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
 
QString16 & insert (const_iterator first, const QString16 &str)
 
template<typename Iterator >
QString16 & insert (const_iterator first, Iterator begin, Iterator end)
 
QString16 & insert (size_type indexStart, const QChar32 *data, size_type numOfChars)
 
QString16 & insert (size_type indexStart, const QString16 &str)
 
QString16 & insert (size_type indexStart, QChar32 c)
 
QString16 & insert (size_type indexStart, QStringView16 str)
 
QString16 & insert (size_type indexStart, QStringView16 str, size_type srcStart, size_type numOfChars)
 
bool isEmpty () const
 
QChar32 last () const
 
size_type lastIndexOf (const QString16 &str, size_type from=-1, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
 
size_type lastIndexOf (QChar32 c, size_type from=-1, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
 
const_iterator lastIndexOfFast (const QString16 &str) const
 
const_iterator lastIndexOfFast (const QString16 &str, const_iterator from, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
 
const_iterator lastIndexOfFast (QChar32 c) const
 
const_iterator lastIndexOfFast (QChar32 c, const_iterator from, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
 
const_iterator lastIndexOfFast (QStringView16 str, const_iterator from, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
 
QString16 left (size_type numOfChars) const
 
QString16 leftJustified (size_type width, QChar32 fill=UCHAR (' '), bool truncate=false) const
 
QStringView16 leftView (size_type numOfChars) const
 
size_type length () const
 
int localeAwareCompare (const QString16 &str) const
 
int localeAwareCompare (QStringView16 str) const
 
QString16 mid (const_iterator iter, size_type numOfChars=-1) const
 
QString16 mid (size_type indexStart, size_type numOfChars=-1) const
 
QStringView16 midView (const_iterator iter, size_type numOfChars=-1) const
 
QStringView16 midView (size_type indexStart, size_type numOfChars=-1) const
 
QString16 normalized (QString16::NormalizationForm mode, QChar32::UnicodeVersion version=QChar32::Unicode_Unassigned) const
 
QString16 & operator+= (const QString16 &other)
 
QString16 & operator+= (QChar32 c)
 
QString16 & operator+= (QChar32::SpecialCharacter c)
 
QString16 & operator+= (QStringView16 str)
 
QString16 & operator= (const QString16 &other) = default
 
QString16 & operator= (QChar32 c)
 
QString16 & operator= (QString16 &&other) = default
 
QString16 & operator= (QStringView16 str)
 
QChar32 operator[] (size_type index) const
 
QString16 & prepend (char32_t c)
 
QString16 & prepend (const QChar32 *data, size_type numOfChars)
 
QString16 & prepend (const QString16 &other)
 
QString16 & prepend (const_iterator iter_begin, const_iterator iter_end)
 
QString16 & prepend (QChar32 c)
 
void push_back (const QString16 &other)
 
void push_back (QChar32 c)
 
void push_front (const QString16 &other)
 
void push_front (QChar32 c)
 
reverse_iterator rbegin ()
 
const_reverse_iterator rbegin () const
 
QString16 & remove (const QRegularExpression16 &regExp)
 
QString16 & remove (const QString16 &str, Qt::CaseSensitivity cs=Qt::CaseSensitive)
 
QString16 & remove (QChar32 c, Qt::CaseSensitivity cs=Qt::CaseSensitive)
 
QString16 & remove (size_type indexStart, size_type numOfChars)
 
reverse_iterator rend ()
 
const_reverse_iterator rend () const
 
QString16 repeated (size_type count) const
 
QString16 & replace (const QChar32 *before, size_type beforeSize, const QChar32 *after, size_type afterSize, Qt::CaseSensitivity cs=Qt::CaseSensitive)
 
QString16 & replace (const QRegularExpression16 &regExp, const QString16 &after)
 
QString16 & replace (const QString16 &before, const QString16 &after, Qt::CaseSensitivity cs=Qt::CaseSensitive)
 
QString16 & replace (const_iterator first, const_iterator last, const QString16 &str)
 
template<typename Iterator >
QString16 & replace (const_iterator first1, const_iterator last1, Iterator first2, Iterator last2)
 
QString16 & replace (QChar32 before, QChar32 after, Qt::CaseSensitivity cs=Qt::CaseSensitive)
 
QString16 & replace (QChar32 c, const QString16 &after, Qt::CaseSensitivity cs=Qt::CaseSensitive)
 
QString16 & replace (size_type indexStart, size_type numOfChars, const QChar32 *data, size_type sizeStr)
 
QString16 & replace (size_type indexStart, size_type numOfChars, const QString16 &str)
 
QString16 & replace (size_type indexStart, size_type numOfChars, const QString16 &str, size_type sizeStr)
 
QString16 & replace (size_type indexStart, size_type numOfChars, QChar32 c)
 
void resize (size_type numOfChars)
 
void resize (size_type numOfChars, QChar32 c)
 
QString16 right (size_type count) const
 
QString16 rightJustified (size_type width, QChar32 fill=UCHAR (' '), bool truncate=false) const
 
QStringView16 rightView (size_type count) const
 
template<typename SP = QStringParser, typename... Ts>
QString16 section (const QString16 &separator, Ts...args) const
 
template<typename SP = QStringParser, typename... Ts>
QString16 section (QChar32 separator, Ts...args) const
 
QString16 simplified () &&
 
QString16 simplified () const &
 
size_type size () const
 
size_type size_storage () const
 
template<typename SP = QStringParser, typename... Ts>
auto split (const QRegularExpression16 &separator, Ts...args) const
 
template<typename SP = QStringParser, typename... Ts>
auto split (const QString16 &separator, Ts...args) const
 
template<typename SP = QStringParser, typename... Ts>
auto split (QChar32 separator, Ts...args) const
 
void squeeze ()
 
bool startsWith (const QString16 &str, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
 
bool startsWith (QChar32 c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
 
bool startsWith (QStringView16 str, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
 
const_storage_iterator storage_begin () const
 
const_storage_iterator storage_end () const
 
const_storage_reverse_iterator storage_rbegin () const
 
const_storage_reverse_iterator storage_rend () const
 
void swap (QString16 &other)
 
QString16 toCaseFolded () &&
 
QString16 toCaseFolded () const &
 
CFStringRef toCFString () const
 
template<typename SP = QStringParser>
double toDouble (bool *ok=nullptr) const
 
template<typename SP = QStringParser>
float toFloat (bool *ok=nullptr) const
 
QString16 toHtmlEscaped () const
 
template<typename R , typename SP = QStringParser>
toInteger (bool *ok=nullptr, int base=10) const
 
QByteArray toLatin1 () const
 
QString16 toLower () &&
 
QString16 toLower () const &
 
NSString * toNSString () const
 
std::wstring toStdWString () const
 
QString16 toUpper () &&
 
QString16 toUpper () const &
 
QByteArray toUtf8 () const
 
QString16 trimmed () &&
 
QString16 trimmed () const &
 
void truncate (size_type length)
 
const uint16_t * utf16 () const
 

Static Public Methods

static int compare (const QString16 &str1, const QString16 &str2, Qt::CaseSensitivity cs=Qt::CaseSensitive)
 
static int compare (QStringView16 str1, QStringView16 str2, Qt::CaseSensitivity cs=Qt::CaseSensitive)
 
static QString16 fromCFString (CFStringRef string)
 
static QString16 fromLatin1 (const char *str, size_type numOfChars=-1)
 
static QString16 fromLatin1 (const QByteArray &str)
 
static QString16 fromNSString (const NSString *string)
 
static QString16 fromStdString (const std::string &str, size_type numOfChars=-1)
 
static QString16 fromStdWString (const std::wstring &str, size_type numOfChars=-1)
 
static QString16 fromUtf16 (const char16_t *str, size_type numOfChars=-1)
 
static QString16 fromUtf8 (const char *str, size_type numOfChars=-1)
 
static QString16 fromUtf8 (const QByteArray &str)
 
static QString16 fromUtf8 (const QString8 &str)
 
static int localeAwareCompare (const QString16 &str1, const QString16 &str2)
 
static int localeAwareCompare (QStringView16 str1, QStringView16 str2)
 
template<typename SP = QStringParser>
static QString16 number (double value, char format= 'g', int precision=6)
 
template<typename V , typename SP = QStringParser>
static QString16 number (V value, int base=10)
 

Related Functions

These are not member functions

bool operator!= (const char (&cString)[N], const QString16 &str)
 
bool operator!= (const QString16 &str, const char (&cString)[N])
 
bool operator!= (const QString16 &str1, const QString16 &str2)
 
QString16 operator+ (const char (&cString)[N], const QString16 &str)
 
QString16 operator+ (const QString16 &str, const char (&cString)[N])
 
QString16 operator+ (const QString16 &str, QChar32 c)
 
QString16 operator+ (const QString16 &str1, const QString16 &str2)
 
QString16 operator+ (QChar32 c, const QString16 &str)
 
QString16 && operator+ (QString16 &&str, const char (&cString)[N])
 
QString16 && operator+ (QString16 &&str, QChar32 c)
 
QString16 && operator+ (QString16 &&str1, const QString16 &str2)
 
bool operator< (const char (&cString)[N], const QString16 &str)
 
bool operator< (const QString16 &str, const char (&cString)[N])
 
bool operator< (const QString16 &str1, const QString16 &str2)
 
QDataStreamoperator<< (QDataStream &stream, const QString16 &str)
 
bool operator<= (const char (&cString)[N], const QString16 &str)
 
bool operator<= (const QString16 &str, const char (&cString)[N])
 
bool operator<= (const QString16 &str1, const QString16 &str2)
 
bool operator== (const char (&cString)[N], const QString16 &str)
 
bool operator== (const QString16 &str, const char (&cString)[N])
 
bool operator== (const QString16 &str1, const QString16 &str2)
 
bool operator> (const char (&cString)[N], const QString16 &str)
 
bool operator> (const QString16 &str, const char (&cString)[N])
 
bool operator> (const QString16 &str1, const QString16 &str2)
 
bool operator>= (const char (&cString)[N], const QString16 &str)
 
bool operator>= (const QString16 &str, const char (&cString)[N])
 
bool operator>= (const QString16 &str1, const QString16 &str2)
 
QDataStreamoperator>> (QDataStream &stream, QString16 &str)
 
void swap (QString16 &str1, QString16 &str2)
 

Detailed Description

QString16 provides a UTF-16 Unicode aware string class which stores a sequence of QChar32 elements. Each QChar32 corresponds to one Unicode code point. Unicode is an international standard which supports the majority of human languages.

CopperSpice also provides QByteArray to store raw bytes and traditional 8-bit null terminated strings. QString8 is the appropriate string class in almost all cases. The QByteArray class is appropriate when storing raw binary data. QString16 should only be used when interfacing with external libraries which expect UTF-16 encoded data.

Using the QString8 class is synonymous with using QString. There is a typedef in CopperSpice which defines QString as equivalent to QString8.

For more information about strings, code points, text encodings, and internationalization refer to Unicode and Internationalization.

Note
Since the API for QString16 is very similar to QString8, refer to the detailed documentation in QString8 for string handling.

Member Typedef Documentation

Provides an STL style const reverse iterator for QString16.

See also
QString16::iterator

Typedef for an integer type representing the distance between two elements in a QString16.

Provides an STL style non-const reverse iterator for QString16.

See also
QString16::const_iterator

Typedef for an integer type representing sizes in a QString16.

Typedef for char16_t.

Typedef for the elements stored in a QString16.

Member Enumeration Documentation

This enum describes the various normalized forms of Unicode text.

ConstantValueDescription
QString16::NormalizationForm_D 0 Canonical Decomposition
QString16::NormalizationForm_C 1 Canonical Decomposition followed by Canonical Composition
QString16::NormalizationForm_KD 2 Compatibility Decomposition
QString16::NormalizationForm_KC 3 Compatibility Decomposition followed by Canonical Composition
See also
normalized(), Unicode Standard Annex #15

Constructor & Destructor Documentation

QString16::QString16 ( )
default

Constructs an empty string.

See also
isEmpty()
QString16::QString16 ( const char16_t *  data)
inline

Constructs a new QString16 from data.

QString16::QString16 ( const QString16 &  other)
default

Copy constructs a new QString16 from other.

See also
operator=()
QString16::QString16 ( QString16 &&  other)
default

Move constructs a new QString16 from other.

QString16::QString16 ( QChar32  c)

Constructs a string of size 1 containing the code point c.

QString16::QString16 ( size_type  numOfChars,
QChar32  c 
)

Constructs a string of the given numOfChars with every code point set to c.

See also
fill()
QString16::QString16 ( QChar32::SpecialCharacter  c)
inline

Constructs a string using the special Unicode character c.

QString16::QString16 ( const QChar32 data,
size_type  numOfChars = -1 
)
inline

Constructs a string with the first numOfChars number of code points pointed to by data. If numOfChars is not specified, the entire null terminated string will be used.

QString16::QString16 ( const_iterator  begin,
const_iterator  end 
)
inline

Constructs a string using the const iterator range begin to end.

template<int N>
QString16::QString16 ( const char (&)  cStr[N])
inline

Constructs a string using the given string literal cStr.

QString16::QString16 ( const QByteArray str)
inline

Constructs a string initialized with str. The entire string is copied including any null characters. The contents of the QByteArray must be valid UTF-8.

This constructor will only be available if you define CS_STRING_ALLOW_UNSAFE.

Warning
It is strongly advised not to use this method. Instead your code should call QString16::fromLatin1() or QString16::fromUtf8().
template<typename Iterator >
QString16::QString16 ( Iterator  begin,
Iterator  end 
)
inline

Constructs a string using the iterator range begin to end. The elements in the range must be implicitly convertible to QChar32.

QString16::QString16 ( QStringView16  str)
inline

Constructs a string using the string view str.

QString16::~QString16 ( )
default

Destroys this string.

Method Documentation

QString16 & QString16::append ( char32_t  c)
inline

Appends the code point c to this string and returns a reference to this string.

QString16 & QString16::append ( const QChar32 data,
size_type  numOfChars 
)
inline

Appends the first numOfChars number of code points pointed to by data.

QString16 & QString16::append ( const QString16 &  other)
inline

Appends the string other to the end of this string. Returns a reference to this string.

QString16 str1 = "free";
QString16 str2 = "dom";
str1.append(str2); // str1 == "freedom"
See also
operator+=(), insert(), prepend()
QString16 & QString16::append ( const_iterator  iter_begin,
const_iterator  iter_end 
)
inline

Appends from iter_begin to iter_end, to the end of this string. Returns a reference to this string.

QString16 & QString16::append ( QChar32  c)
inline

Appends the code point c to this string and returns a reference to this string.

QString16 & QString16::append ( QStringView16  str)
inline

Appends the given string view str to this string. Returns a reference to this string.

QString16 & QString16::append ( QStringView16  str,
size_type  indexStart,
size_type  numOfChars 
)
inline

Appends the given string view str to this string, beginning at position indexStart in str and continuing for the length numOfChars. Returns a reference to this string.

QChar32 QString16::at ( size_type  index) const
inline

Returns the code point at the given position index in the string. The index must be a valid position in the string.

str = "Sourdough bread is a trademark of San Francisco";
for (int i = 0; i < str.size(); ++i) {
if (str.at(i) >= QUChar('a') && str.at(i) <= QUChar('f')) {
qDebug() << "Found character in range [a-f]";
}
}
See also
operator[]()
QChar32 QString16::back ( ) const
inline

Returns the last code point in this string.

See also
front(), at(), operator[]()
iterator QString16::begin ( )
inline

Returns an STL style iterator pointing to the first code point in the string.

See also
constBegin(), end()
const_iterator QString16::begin ( ) const
inline

Returns a const STL style iterator pointing to the first code point in the string.

const_iterator QString16::cbegin ( ) const
inline

Returns a const STL style iterator pointing to the first code point in the string.

See also
begin(), cend()
const_iterator QString16::cend ( ) const
inline

Returns a const STL style iterator pointing to the imaginary item after the last code point in the string.

See also
cbegin(), end()
void QString16::chop ( size_type  numOfChars)

Removes numOfChar code points counting from the end of the string. If numOfChar is greater than size() the result is an empty string.

QString str("LOGOUT");
str.chop(3); // str == "LOG"

To remove characters from the beginning of the string, use remove().

See also
truncate(), resize(), remove()
void QString16::clear ( )
inline

Clears the contents of the string and makes it empty.

See also
resize(), isEmpty()
int QString16::compare ( const QString16 &  str,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
) const
inline

Compares this string with the string str. If cs is Qt::CaseSensitive the comparison is case sensitive, otherwise the comparison is case insensitive.

  • if this string is less than str, returns -1
  • if this string is equal to str, returns 0
  • if this string is greater than str, returns 1
int QString16::compare ( const QString16 &  str1,
const QString16 &  str2,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
)
inlinestatic

Compares str1 with str2. If cs is Qt::CaseSensitive the comparison is case sensitive, otherwise the comparison is case insensitive.

  • if str1 is less than str2, returns -1
  • if str1 is equal to str2, returns 0
  • if str1 is greater than str2, returns 1
int x = QString16::compare("aUtO", "AuTo", Qt::CaseInsensitive); // x == 0
int y = QString16::compare("auto", "Car", Qt::CaseSensitive); // y > 0
int z = QString16::compare("auto", "Car", Qt::CaseInsensitive); // z < 0
See also
operator==(), operator<(), operator>()
int QString16::compare ( QStringView16  str,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
) const
inline

Compares this string with the string view str. If cs is Qt::CaseSensitive the comparison is case sensitive, otherwise the comparison is case insensitive.

  • if this string is less than str, returns -1
  • if this string is equal to str, returns 0
  • if this string is greater than str, returns 1
int QString16::compare ( QStringView16  str1,
QStringView16  str2,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
)
static

Compares string view str1 with the string view str2. If cs is Qt::CaseSensitive the comparison is case sensitive, otherwise the comparison is case insensitive.

  • if str1 is less than str2, returns -1
  • if str1 is equal to str2, returns 0
  • if str1 is greater than str2, returns 1
const_iterator QString16::constBegin ( ) const
inline

Returns a const STL style iterator pointing to the first code point in the string.

See also
begin(), constEnd()
const char16_t * QString16::constData ( ) const
inline

Returns a pointer to the null terminated data stored in the string. The pointer is valid until the string is modified.

See also
data(), operator[]()
const_iterator QString16::constEnd ( ) const
inline

Returns a const STL style iterator pointing to the imaginary item after the last code point in the string.

See also
constBegin(), end()
bool QString16::contains ( char  ch,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
) const
inline

Returns true if this string contains an occurrence of the character ch, otherwise returns false. If cs is Qt::CaseSensitive the search is case sensitive, otherwise the search is case insensitive.

bool QString16::contains ( const QRegularExpression16 regExp) const
inline

Returns true if this string contains an occurrence of the regular expression regExp, otherwise it returns false.

QRegularExpression16 regExp("[0-9]$");
// obsolete syntax, indexIn method removed
bool found_A = regExp.indexIn(child->objectName()) != -1;
// use contains()
bool found_B = child->objectName().contains(regExp);
bool QString16::contains ( const QString16 &  str,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
) const

Returns true if this string contains an occurrence of the string str, otherwise it returns false. If cs is Qt::CaseSensitive the search is case sensitive, otherwise the search is case insensitive.

QString16 str = "Peter Pan";
str.contains("peter", Qt::CaseInsensitive); // returns true
See also
indexOf(), count()
bool QString16::contains ( QChar32  c,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
) const

Returns true if this string contains an occurrence of the character c, otherwise returns false. If cs is Qt::CaseSensitive the search is case sensitive, otherwise the search is case insensitive.

bool QString16::contains ( QStringView16  str,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
) const

Returns true if this string contains an occurrence of the string view str, otherwise it returns false. If cs is Qt::CaseSensitive the search is case sensitive, otherwise the search is case insensitive.

See also
indexOf(), count()
size_type QString16::count ( ) const
inline

Equivalent to calling size().

size_type QString16::count ( const QRegularExpression16 regExp) const

Returns the number of occurrences of the regular expression regExp in the string.

size_type QString16::count ( const QString16 &  str,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
) const

Returns the number of (potentially overlapping) occurrences of the string str in this string. If cs is Qt::CaseSensitive the search is case sensitive, otherwise the search is case insensitive.

See also
contains(), indexOf()
size_type QString16::count ( QChar32  c,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
) const

Returns the number of occurrences of character c in the string. If cs is Qt::CaseSensitive the search is case sensitive, otherwise the search is case insensitive.

size_type QString16::count ( QStringView16  str,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
) const

Returns the number of occurrences of the string view str in this string. If cs is Qt::CaseSensitive the search is case sensitive, otherwise the search is case insensitive.

const_reverse_iterator QString16::crbegin ( ) const
inline

Returns an STL style iterator pointing to the last code point in the string, in reverse order.

See also
begin(), rbegin(), rend()
const_reverse_iterator QString16::crend ( ) const
inline

Returns a const STL style iterator pointing to the imaginary item before the first code point in the string, in reverse order.

See also
end(), rbegin(), rend()
const char16_t * QString16::data ( ) const
inline

Returns a pointer to the null terminated data stored in the string. The pointer is valid until the string is modified.

See also
constData(), operator[]()
bool QString16::empty ( ) const
inline

Returns true if the string has no characters, otherwise returns false.

See also
size()
iterator QString16::end ( )
inline

Returns an STL style iterator pointing to the imaginary item after the last code point in the string.

See also
begin(), constEnd()
const_iterator QString16::end ( ) const
inline

Returns a const STL style iterator pointing to the imaginary item after the last code point in the string.

bool QString16::endsWith ( const QString16 &  str,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
) const

Returns true if the string ends with str, otherwise returns false. If cs is Qt::CaseSensitive the search is case sensitive, otherwise the search is case insensitive.

QString16 str = "fruitcake";
str.endsWith("cake"); // returns true
str.endsWith("pie"); // returns false
See also
startsWith()
bool QString16::endsWith ( QChar32  c,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
) const

Returns true if the current string ends with c, otherwise returns false.

bool QString16::endsWith ( QStringView16  str,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
) const

Returns true if the current string ends with the string view str, otherwise returns false. If cs is Qt::CaseSensitive the search is case sensitive, otherwise the search is case insensitive.

QString16 & QString16::fill ( QChar32  c,
size_type  numOfChars = -1 
)

Sets every character in the string to character c. If numOfChars is not the default value of -1, the string is resized to the value of numOfChars before the fill is done.

QString16 str = "San Francisco";
str.fill('z'); // str == "zzzzzzzzzzzzz"
str.fill('A', 2); // str == "AA"
See also
resize()
QChar32 QString16::first ( ) const
inline

Returns the first code point in this string.

See also
back(), at(), operator[]()
template<typename SP = QStringParser, typename... Ts>
QString16 QString16::formatArg ( Ts &&...  args) const
nodiscardinline

Wrapper for QStringParser::formatArg(). In order to use this method in your application include the <QStringParser> header file.

template<typename SP = QStringParser, typename... Ts>
QString16 QString16::formatArgs ( Ts &&...  args) const
nodiscardinline

Wrapper for QStringParser::formatArgs(). In order to use this method in your application include the <QStringParser> header file.

QString16 QString16::fromCFString ( CFStringRef  string)
static

Constructs a new QString containing a copy of the string CFString.

Note
This method is only available on Mac OS X.
QString16 QString16::fromLatin1 ( const char *  str,
size_type  numOfChars = -1 
)
static

Returns a QString16 containing the first numOfChars number of Latin-1 characters specified in str. If value for numOfChars is -1 the entire str is used.

See also
toLatin1(), fromUtf8()
QString16 QString16::fromLatin1 ( const QByteArray str)
static

Returns a QString16 containing the Latin-1 string str.

See also
toLatin1(), fromUtf8()
QString16 QString16::fromNSString ( const NSString *  string)
static

Constructs a new QString containing a copy of the string NSString.

Note
This method is only available on Mac OS X.
QString16 QString16::fromStdString ( const std::string &  str,
size_type  numOfChars = -1 
)
static

Returns a QString16 containing the std::string str.

QString16 QString16::fromStdWString ( const std::wstring &  str,
size_type  numOfChars = -1 
)
static

Returns a QString16 containing the std::wstring str.

QString16 QString16::fromUtf16 ( const char16_t *  str,
size_type  numOfChars = -1 
)
static

Returns a QString16 containing the first numOfChars number of characters from the UTF-16 string str. If the value for numOfChars is -1 the str must be null terminated.

QString16 QString16::fromUtf8 ( const char *  str,
size_type  numOfChars = -1 
)
static

Returns a QString16 containing the first numOfChars number of characters from the C string str. If the value for numOfChars is -1 the str must be null terminated.

See also
toUtf8(), fromLatin1()
QString16 QString16::fromUtf8 ( const QByteArray str)
static

Returns a QString16 containing the UTF-8 string str.

See also
toUtf8(), fromLatin1()
QString16 QString16::fromUtf8 ( const QString8 str)
static

Returns a QString16 containing the UTF-8 string str.

QChar32 QString16::front ( ) const
inline

Returns the first code point in this string.

See also
back(), at(), operator[]()
size_type QString16::indexOf ( const QRegularExpression16 regExp,
size_type  from = 0 
) const
inline

Returns the index position of the first occurrence of the regular expression regExp in the string, searching forward from the index position from. Returns -1 if regExp is not found.

size_type QString16::indexOf ( const QString16 &  str,
size_type  from = 0,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
) const
inline

Returns the index position of the first occurrence of str in this string. The search begins at position from. Returns -1 if str is not found.

If from is -1 the search starts at the last character, if from is -2 the search starts at the next to last character, and so on. If cs is Qt::CaseSensitive the search is case sensitive, otherwise the search is case insensitive.

QString16 x = "sticky question";
QString16 y = "sti";
x.indexOf(y); // returns 0
x.indexOf(y, 1); // returns 10
x.indexOf(y, 10); // returns 10
x.indexOf(y, 11); // returns -1
See also
lastIndexOf(), contains(), count()
size_type QString16::indexOf ( QChar32  c,
size_type  from = 0,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
) const
inline

Returns the index position of the first occurrence of the character c in the string, searching forward from index position from. Returns -1 if c is not found.

If cs is Qt::CaseSensitive the search is case sensitive, otherwise the search is case insensitive.

const_iterator QString16::indexOfFast ( const QRegularExpression16 regExp) const
inline

Returns the iterator position of the first occurrence of the regular expression regExp in the string. Returns the end iterator if the regExp is not found.

QString16 str = "the minimum value";
auto iter = str.indexOfFast(QRegularExpression("m[aeiou]")); // returns an iterator
const_iterator QString16::indexOfFast ( const QRegularExpression16 regExp,
const_iterator  from 
) const

Returns the iterator position of the first occurrence of the string view str in the string, searching forward from iterator position from. Returns the end iterator if str is not found.

const_iterator QString16::indexOfFast ( const QString16 &  str) const
inline

Returns an iterator to the first occurrence of str in this string. Returns the end iterator if str is not found.

const_iterator QString16::indexOfFast ( const QString16 &  str,
const_iterator  from = cbegin(),
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
) const
inline

Returns an iterator to the first occurrence of str in this string, searching forward from iterator from. Returns the end iterator if str is not found.

If cs is Qt::CaseSensitive the search is case sensitive, otherwise the search is case insensitive.

const_iterator QString16::indexOfFast ( QChar32  c) const
inline

Returns an iterator to the first occurrence of c in this string. Returns the end iterator if c is not found.

const_iterator QString16::indexOfFast ( QChar32  c,
const_iterator  from = cbegin(),
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
) const
inline

Returns an iterator to the first occurrence of c in this string, searching forward from iterator from. Returns the end iterator if c is not found.

If cs is Qt::CaseSensitive the search is case sensitive, otherwise the search is case insensitive.

const_iterator QString16::indexOfFast ( QStringView16  str,
const_iterator  from,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
) const
inline

Returns the iterator position of the first occurrence of the string view str in the string, searching forward from iterator position from. Returns the end iterator if str is not found.

If cs is Qt::CaseSensitive the search is case sensitive, otherwise the search is case insensitive.

QString16 & QString16::insert ( const_iterator  first,
const QString16 &  str 
)
inline

Beginning at position first in the current string, insert str. Returns a reference to this string.

template<typename Iterator >
QString16 & QString16::insert ( const_iterator  first,
Iterator  begin,
Iterator  end 
)
inline

Beginning at position first in the current string, insert the range of characters from begin to end. Returns a reference to this string.

QString16 & QString16::insert ( size_type  indexStart,
const QChar32 data,
size_type  numOfChars 
)
inline

At position indexStart in the string, insert the first numOfChars number of code points pointed to by data.

QString16 & QString16::insert ( size_type  indexStart,
const QString16 &  str 
)
inline

Inserts the string str at the given indexStart and returns a reference to this string. If the given indexStart is greater than size() the string is first extended using resize().

QString16 str = "Meal";
str.insert(1, QString16("ontr")); // str == "Montreal"
See also
append(), prepend(), replace(), remove()
QString16 & QString16::insert ( size_type  indexStart,
QChar32  c 
)
inline

Inserts c at the given index indexStart in the string.

QString16 & QString16::insert ( size_type  indexStart,
QStringView16  str 
)
inline

Inserts the string view str at the given position indexStart in this string. Returns a reference to this string.

QString16 & QString16::insert ( size_type  indexStart,
QStringView16  str,
size_type  srcStart,
size_type  numOfChars 
)
inline

Inserts the string view str at the given position indexStart in the string, beginning at the position srcStart in str and continuing for the length numOfChars.

Returns a reference to this string.

bool QString16::isEmpty ( ) const
inline

Returns true if the string has no characters, otherwise returns false.

QString().isEmpty(); // returns true
QString("").isEmpty(); // returns true
QString("x").isEmpty(); // returns false
QString("abc").isEmpty(); // returns false
See also
size()
QChar32 QString16::last ( ) const
inline

Returns the last code point in this string.

See also
front(), at(), operator[]()
size_type QString16::lastIndexOf ( const QString16 &  str,
size_type  from = -1,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
) const
inline

Returns the index position of the last occurrence of the string str in this 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 the search starts at the next to last character, and so on. If cs is Qt::CaseSensitive the search is case sensitive, otherwise the search is case insensitive.

QString16 x = "crazy azimuths";
QString16 y = "az";
x.lastIndexOf(y); // returns 6
x.lastIndexOf(y, 6); // returns 6
x.lastIndexOf(y, 5); // returns 2
x.lastIndexOf(y, 1); // returns -1
See also
indexOf(), contains(), count()
size_type QString16::lastIndexOf ( QChar32  c,
size_type  from = -1,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
) const
inline

Returns the index position of the last occurrence of the character c, searching backward from position from. Returns -1 if str is not found.

If cs is Qt::CaseSensitive the search is case sensitive, otherwise the search is case insensitive.

const_iterator QString16::lastIndexOfFast ( const QString16 &  str) const
inline

Returns an iterator to the last occurrence of str in this string. Returns the end iterator if str is not found.

const_iterator QString16::lastIndexOfFast ( const QString16 &  str,
const_iterator  from = cend(),
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
) const
inline

Returns an iterator to the first occurrence of str in this string, searching backward from iterator from. Returns the end iterator if str is not found.

If cs is Qt::CaseSensitive the search is case sensitive, otherwise the search is case insensitive.

const_iterator QString16::lastIndexOfFast ( QChar32  c) const
inline

Returns an iterator to the last occurrence of c in this string. Returns the end iterator if c is not found.

const_iterator QString16::lastIndexOfFast ( QChar32  c,
const_iterator  from = cend(),
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
) const
inline

Returns an iterator to the last occurrence of c in this string, searching backward from iterator from. Returns the end iterator if c is not found.

If cs is Qt::CaseSensitive the search is case sensitive, otherwise the search is case insensitive.

const_iterator QString16::lastIndexOfFast ( QStringView16  str,
const_iterator  from,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
) const
inline

Returns the iterator position of the last occurrence of the string view str in this string, searching backward from iterator position from. Returns the end iterator if str is not found.

If from is -1 the search starts at the last character, if from is -2 the search starts at the next to last character, and so on. If cs is Qt::CaseSensitive the search is case sensitive, otherwise the search is case insensitive.

QString16 QString16::left ( size_type  numOfChars) const
nodiscard

Returns a new QString16 containing the first numOfChars code points in this string. The entire string is returned if numOfChars is greater than size() or less than zero.

QString16 str1 = "Pineapple";
QString16 str2 = x.left(4); // str1 == "Pine"
See also
leftView(), right(), mid(), startsWith()
QString16 QString16::leftJustified ( size_type  width,
QChar32  fill = UCHAR(' '),
bool  truncate = false 
) const
nodiscard

Returns a string of size width that contains this string padded by the fill character. If truncate is false and the size() of the string is more than the value of width, then the returned string is a copy of the string.

QString16 s = "apple";
QString16 t = s.leftJustified(8, '.'); // t == "apple..."

If truncate is true and the size() of the string is more than width, then any characters in a copy of the string after position width are removed and the copy is returned.

QString16 str = "Pineapple";
str = str.leftJustified(5, '.', true); // str == "Pinea"
See also
rightJustified()
QStringView16 QString16::leftView ( size_type  numOfChars) const
nodiscard

Returns a QStringView16 containing the first numOfChars code points in this string. The entire string is returned if numOfChars is greater than size() or less than zero.

QString16 str = "Pineapple";
QStringView16 sv = str.leftRef(4); // sv == "Pine"
See also
rightView(), midView()
size_type QString16::length ( ) const
inline

Returns the number of characters in this string. This method is the same as calling size().

See also
resize()
int QString16::localeAwareCompare ( const QString16 &  str) const
inline

Compares string str with this string object and returns an integer based on the sort relationship of the strings. The comparison is performed platform dependent.

  • if this string is less than str, returns -1
  • if this string is equal to str, returns 0
  • if this string is greater than str, returns 1
int QString16::localeAwareCompare ( const QString16 &  str1,
const QString16 &  str2 
)
inlinestatic

Compares string str1 with string str2 and returns an integer based on the sort relationship of the strings. The comparison is performed platform dependent.

  • if str1 is less than str2, returns -1
  • if str1 is equal to str2, returns 0
  • if str1 is greater than str2, returns 1
int QString16::localeAwareCompare ( QStringView16  str) const
inline

Compares this string with the string view str and returns an integer based on the sort relationship of the strings. The comparison is performed platform dependent.

  • if this string is less than str, returns -1
  • if this string is equal to str, returns 0
  • if this string is greater than str, returns 1
int QString16::localeAwareCompare ( QStringView16  str1,
QStringView16  str2 
)
static

Compares string view str1 with string view str2 and returns an integer based on the sort relationship of the strings. The comparison is performed platform dependent.

  • if str1 is less than str2, returns -1
  • if str1 is equal to str2, returns 0
  • if str1 is greater than str2, returns 1
QString16 QString16::mid ( const_iterator  iter,
size_type  numOfChars = -1 
) const
nodiscard

Returns a string containing numOfChars characters of this string, starting at the iterator position iter.

QString16 QString16::mid ( size_type  indexStart,
size_type  numOfChars = -1 
) const
nodiscard

Returns a string containing numOfChars characters of this string, starting at the position indexStart.

Returns an empty string if the index exceeds the length of the string. If there are less than numOfChars characters available in the string, starting at the given index, or if numOfChars is -1, the method returns all characters available from the specified index to the end of the string.

QString16 x = "Nine pineapples";
QString16 y = x.mid(5, 4); // y == "pine"
QString16 z = x.mid(5); // z == "pineapples"
See also
left(), right()
QStringView16 QString16::midView ( const_iterator  iter,
size_type  numOfChars = -1 
) const

Returns a QStringView16 containing the code points starting at iterator position iter for a length of numOfChars.

QStringView16 QString16::midView ( size_type  indexStart,
size_type  numOfChars = -1 
) const

Returns a QStringView16 containing the code points starting at indexStart for a length of numOfChars.

  • If the position exceeds the length of this string an empty QStringView is returned.
  • The entire string is returned if there are less than numOfChars characters in this string, starting at the given position.
  • The entire string is returned if numOfChars is -1.
QString16 str = "Nine pineapples";
QStringView16 sv1 = str.midView(5, 4); // sv1 == "pine"
QStringView16 sv2 = str.midView(5); // sv2 == "pineapples"
See also
leftView(), rightView()
QString16 QString16::normalized ( QString16::NormalizationForm  mode,
QChar32::UnicodeVersion  version = QChar32::Unicode_Unassigned 
) const
nodiscard

Returns the string in the given Unicode normalization mode, according to the given version of the Unicode standard.

template<typename SP = QStringParser>
QString16 QString16::number ( double  value,
char  format = 'g',
int  precision = 6 
)
nodiscardinlinestatic

Wrapper for QStringParser::number(). In order to use this method in your application include the <QStringParser> header file.

template<typename V , typename SP = QStringParser>
QString16 QString16::number ( value,
int  base = 10 
)
nodiscardinlinestatic

Wrapper for QStringParser::number(). In order to use this method in your application include the <QStringParser> header file.

QString16 & QString16::operator+= ( const QString16 &  other)
inline

Appends the string other to the end of this string and returns a reference to this string.

QString16 str1 = "free";
QString16 str2 = "dom";
str1 += str2; // str1 == "freedom"
See also
append(), prepend()
QString16 & QString16::operator+= ( QChar32  c)
inline

Appends c to this string and returns a reference to this string.

QString16 & QString16::operator+= ( QChar32::SpecialCharacter  c)
inline

Appends the special Unicode character c to this string and returns a reference to this string.

QString16 & QString16::operator+= ( QStringView16  str)
inline

Appends the string view str to this string.

QString16 & QString16::operator= ( const QString16 &  other)
default

Copy assigns from other and returns a reference to this object.

QString16 & QString16::operator= ( QChar32  c)
inline

Assigns c to this string and returns a reference to this string.

QString16 & QString16::operator= ( QString16 &&  other)
default

Move assigns from other and returns a reference to this object.

QString16 & QString16::operator= ( QStringView16  str)
inline

Assigns the string view str to this string and returns a reference to this string.

QChar32 QString16::operator[] ( size_type  index) const
inline

Returns the code point at the specified index in the string. Equivalent to calling at(index).

QString16 & QString16::prepend ( char32_t  c)
inline

Prepends the character c to this string and returns a reference to this string.

QString16 & QString16::prepend ( const QChar32 data,
size_type  numOfChars 
)
inline

Prepends the first numOfChars number of characters pointed to by data.

QString16 & QString16::prepend ( const QString16 &  other)
inline

Prepends the string other to the beginning of this string and returns a reference to this string.

QString16 x = "ship";
QString16 y = "air";
x.prepend(y); // x == "airship"
See also
append(), insert()
QString16 & QString16::prepend ( const_iterator  iter_begin,
const_iterator  iter_end 
)
inline

Prepends from iter_begin to iter_end. Returns a reference to this string.

QString16 & QString16::prepend ( QChar32  c)
inline

Prepends the character c to this string and returns a reference to this string.

void QString16::push_back ( const QString16 &  other)
inline

This method is equivalent to appending the given other string onto the end of this string. It is the same as append(other).

See also
append()
void QString16::push_back ( QChar32  c)
inline

Appends the given c character to the end of this string.

void QString16::push_front ( const QString16 &  other)
inline

This method is equivalent to prepending the given other string to the beginning of this string. It is the same as prepend(other).

See also
prepend()
void QString16::push_front ( QChar32  c)
inline

Prepends the given c character to the beginning of this string.

reverse_iterator QString16::rbegin ( )
inline

Returns an STL style iterator pointing to the last code point in the string, in reverse order.

See also
begin(), crbegin(), rend()
const_reverse_iterator QString16::rbegin ( ) const
inline

Returns a const STL style iterator pointing to the last code point in the string, in reverse order.

QString16 & QString16::remove ( const QRegularExpression16 regExp)
inline

Removes every occurrence of the regular expression regExp in the string and returns a reference to the string.

QString16 str = "trombone";
str.remove(QRegularExpression("[aeiou].")); // str == "trbe"
See also
indexOf(), lastIndexOf(), replace()
QString16 & QString16::remove ( const QString16 &  str,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
)

Removes every occurrence of the given str in this string and returns a reference to this string. If cs is Qt::CaseSensitive the search is case sensitive, otherwise the search is case insensitive.

This is the same as replace(str, "", cs).

See also
replace()
QString16 & QString16::remove ( QChar32  c,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
)

Removes every occurrence of the character c in this string, and returns a reference to this string. If cs is Qt::CaseSensitive the search is case sensitive, otherwise the search is case insensitive.

QString16 str = "Ali Baba";
str.remove(QChar32('a'), Qt::CaseInsensitive); // str == "li Bb"

This is the same as replace(c, "", cs).

See also
replace()
QString16 & QString16::remove ( size_type  indexStart,
size_type  numOfChars 
)

Removes numOfChars code points from the string, starting at the given indexStart index. Returns a reference to the string. If (indexStart + numOfChars) is beyond the end of the string, the string is truncated at the specified indexStart.

QString16 str = "Montreal";
str.remove(1, 4); // str == "Meal"
See also
insert(), replace()
reverse_iterator QString16::rend ( )
inline

Returns an STL style iterator pointing to the imaginary item before the first code point in the string, in reverse order.

See also
begin(), crbegin(), rend()
const_reverse_iterator QString16::rend ( ) const
inline

Returns a const STL style iterator pointing to the imaginary item before the first code point in the string, in reverse order.

QString16 QString16::repeated ( size_type  count) const
nodiscard

Returns a copy of this string repeated the specified number of count. If the value for times is less than 1, an empty string is returned.

QString16 str("ab");
return str.repeated(4); // returns "abababab"
QString16 & QString16::replace ( const QChar32 before,
size_type  beforeSize,
const QChar32 after,
size_type  afterSize,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
)

Replaces each occurrence in this string of the first beforeSize characters of before with the first afterSize characters of after and returns a reference to this string. If cs is Qt::CaseSensitive the search is case sensitive, otherwise the search is case insensitive.

QString16 & QString16::replace ( const QRegularExpression16 regExp,
const QString16 &  after 
)

Replaces every occurrence of the regular expression regExp in the string with after. Returns a reference to this string.

QString16 str = "banana";
str.replace(QRegularExpression("a[mn]"), "ox"); // str == "boxoxa"

For regular expressions containing capturing parentheses in the pattern, occurrences of \1, \2, ..., in the passed parameter string "after" are replaced with the corresponding capture.

QString16 str = "half a <i>banana</i>";
str.replace(QRegularExpression("<i>([^<]*)</i>"), "\\emph{\\1}"); // str == "half a \\emph{banana}"
See also
indexOf(), lastIndexOf(), remove(), QRegularExpressionMatch::captured()
QString16 & QString16::replace ( const QString16 &  before,
const QString16 &  after,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
)

Replaces every occurrence of the string before with the string after and returns a reference to this string. If cs is Qt::CaseSensitive the search is case sensitive, otherwise the search is case insensitive.

QString16 str = "colour behavior flavour neighbour";
str.replace(QString("ou"), QString("o")); // str == "color behavior flavor neighbor"

It is of value to note the replacement text is not rescanned after it is inserted.

QString16 str = "xxxxxx";
str.replace("xx", "x"); // str == "xxx"
QString16 & QString16::replace ( const_iterator  first,
const_iterator  last,
const QString16 &  str 
)
inline

Beginning at position first replace the characters up to but not including last with str. Returns a reference to this string.

template<typename Iterator >
QString16 & QString16::replace ( const_iterator  first1,
const_iterator  last1,
Iterator  first2,
Iterator  last2 
)
inline

Replace the range from first1 to last1 with the characters from first2 to last2. Returns a reference to this string.

QString16 & QString16::replace ( QChar32  before,
QChar32  after,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
)

Replaces every occurrence of the QChar32 before with the QChar32 after and returns a reference to this string. If cs is Qt::CaseSensitive the search is case sensitive, otherwise the search is case insensitive.

QString16 & QString16::replace ( QChar32  c,
const QString16 &  after,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
)

Replaces every occurrence of the QChar32 c in this string with the string after and returns a reference to this string. If cs is Qt::CaseSensitive the search is case sensitive, otherwise the search is case insensitive.

QString16 & QString16::replace ( size_type  indexStart,
size_type  numOfChars,
const QChar32 data,
size_type  sizeStr 
)
inline

Beginning at position indexStart in this string, replace the next numOfChars with the first sizeStr code points of data. Returns a reference to this string.

QString16 & QString16::replace ( size_type  indexStart,
size_type  numOfChars,
const QString16 &  str 
)
inline

Beginning at position indexStart in this string, replace the next numOfChars with string str. Returns a reference to this string.

QString16 x = "Say yes";
QString16 y = "no";
x.replace(4, 3, y); // x == "Say no"
See also
insert(), remove()
QString16 & QString16::replace ( size_type  indexStart,
size_type  numOfChars,
const QString16 &  str,
size_type  sizeStr 
)
inline

Beginning at position indexStart in this string, replace the next numOfChars with the first sizeStr number of code points from the string str. Returns a reference to this string.

QString16 & QString16::replace ( size_type  indexStart,
size_type  numOfChars,
QChar32  c 
)
inline

Beginning at position indexStart in this string, replace the next numOfChars with a single character c. Returns a reference to this string.

void QString16::resize ( size_type  numOfChars)
inline

Sets the size of the string to numOfChars code points. If numOfChars is greater than the current size the string is extended to make it numOfChars code points long with the extra code points added to the end. The new code points are uninitialized.

If numOfChars is less than the current size, characters are removed from the end.

QString16 s = "Hello world";
s.resize(5); // s == "Hello"
s.resize(8); // s == "Hello???" (where ? stands for any character)

If you want to append a certain number of identical code points to the string, use operator+=() as follows rather than resize().

QString16 t = "Hello";
t += QString(10, 'X'); // t == "HelloXXXXXXXXXX"

If you want to expand the string so that it reaches a certain width and fill the new positions with a particular code point, use the leftJustified() method:

If size is negative, it is equivalent to passing zero.

QString16 r = "Hello";
r = r.leftJustified(10, ' '); // r == "Hello "
See also
truncate()
void QString16::resize ( size_type  numOfChars,
QChar32  c 
)
inline

Sets the size of the string to numOfChars code points. If numOfChars is greater than the current size the string is extended to make it numOfChars characters long with the extra code points added to the end.

The new code points are initialized to c.

QString16 QString16::right ( size_type  count) const
nodiscard

Returns a substring containing the count rightmost code points of the string. The entire string is returned if n is greater than size() or less than zero.

QString16 x = "Pineapple";
QString16 y = x.right(5); // y == "apple"
See also
left(), mid(), endsWith()
QString16 QString16::rightJustified ( size_type  width,
QChar32  fill = UCHAR(' '),
bool  truncate = false 
) const
nodiscard

Returns a string of size() width that contains the fill character followed by the string.

If truncate is false and the size() of the string is more than the width, the returned string is a copy of the string.

QString16 s = "apple";
QString16 t = s.rightJustified(8, '.'); // t == "...apple"

If truncate is true and the size() of the string is more than width, the resulting string is truncated at position width.

QString16 str = "Grapefruit";
str = str.rightJustified(5, '.', true); // str == "Grape"
See also
leftJustified()
QStringView16 QString16::rightView ( size_type  count) const
nodiscard

Returns a QStringView16 containing the last count code points in this string. The entire string is returned if numOfChars is greater than size() or less than zero.

QString16 str = "Pineapple";
QStringView16 sv = str.rightView(5); // y == "apple"
See also
leftView(), midView()
template<typename SP = QStringParser, typename... Ts>
QString16 QString16::section ( const QString16 &  separator,
Ts...  args 
) const
inline

Wrapper for QStringParser::section(). In order to use this method in your application include the <QStringParser> header file.

template<typename SP = QStringParser, typename... Ts>
QString16 QString16::section ( QChar32  separator,
Ts...  args 
) const
inline

Wrapper for QStringParser::section(). In order to use this method in your application include the <QStringParser> header file.

QString16 csv = "firstName,middleName,lastName,phone";
str = csv.section(',', 2, 2); // str == "lastName"
QString16 QString16::simplified ( ) &&
nodiscard

Returns a string that has whitespace removed from the start and the end, and that has each sequence of internal whitespace replaced with a single space. This method is only called if this string is an rvalue, this occurs when the string is a temporary or has been moved.

Refer to the const reference version of simplified().

QString16 QString16::simplified ( ) const &
nodiscard

Returns a string that has whitespace removed from the start and the end, and that has each sequence of internal whitespace replaced with a single space.

Whitespace means any character for which QChar32::isSpace() returns true. This includes the ASCII characters '\t', '\n', '\v', '\f', '\r', and ' '.

QString16 str = " lots\t of\n whitespace\r\n ";
str = str.simplified(); // str == "lots of whitespace";
See also
trimmed()
size_type QString16::size ( ) const
inline

Returns the number of code points in this string.

The last character in the string is at position size() - 1. In addition, QString16 ensures the character at position size() is always '\0' so you can use the return value of data() and constData() as arguments to functions which expect null terminated strings.

QString16 str = "CopperSpice";
int len = str.size(); // len == 11
str.data()[0]; // returns 'C'
str.data()[4]; // returns 'e'
str.data()[11]; // returns '\0'
See also
isEmpty(), resize()
size_type QString16::size_storage ( ) const
inline

Returns the number of storage units in this string. The storage size is the actual bytes required in the underlying container for a string. This value will usually be larger than size().

It is normally only used when passing a QString16 to a C API which expects a pointer and a length.

template<typename SP = QStringParser, typename... Ts>
QList< QString16 > QString16::split ( const QRegularExpression16 separator,
Ts...  args 
) const
inline

Wrapper for QStringParser::split(). In order to use this method in your application include the <QStringParser> header file.

template<typename SP = QStringParser, typename... Ts>
QList< QString16 > QString16::split ( const QString16 &  separator,
Ts...  args 
) const
inline

Wrapper for QStringParser::split(). In order to use this method in your application include the <QStringParser> header file.

template<typename SP = QStringParser, typename... Ts>
QList< QString16 > QString16::split ( QChar32  separator,
Ts...  args 
) const
inline

Wrapper for QStringParser::split(). In order to use this method in your application include the <QStringParser> header file.

void QString16::squeeze ( )
inline

Releases any memory not required to store the character data. In general you will rarely ever need to call this method.

bool QString16::startsWith ( const QString16 &  str,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
) const

Returns true if the current string starts with str, otherwise returns false. If cs is Qt::CaseSensitive the search is case sensitive, otherwise the search is case insensitive.

QString16 str = "Bananas";
str.startsWith("Ban"); // returns true
str.startsWith("Car"); // returns false
See also
endsWith()
bool QString16::startsWith ( QChar32  c,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
) const

Returns true if the string starts with c, otherwise returns false. If cs is Qt::CaseSensitive the search is case sensitive, otherwise the search is case insensitive.

bool QString16::startsWith ( QStringView16  str,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
) const

Returns true if the current string starts with the string view str, otherwise returns false. If cs is Qt::CaseSensitive the search is case sensitive, otherwise the search is case insensitive.

const_storage_iterator QString16::storage_begin ( ) const
inline

Returns a const STL style iterator pointing to the first storage unit in the string. In UTF-16 a code point such as the Greek letter Delta is one code point and requires one storage unit.

See also
size_storage()
const_storage_iterator QString16::storage_end ( ) const
inline

Returns a const STL style iterator pointing to the imaginary item after the last storage unit in the string.

See also
size_storage()
const_storage_reverse_iterator QString16::storage_rbegin ( ) const
inline

Returns a const STL style iterator pointing to the last storage unit in the string, in reverse order.

See also
size_storage()
const_storage_reverse_iterator QString16::storage_rend ( ) const
inline

Returns a const STL style iterator pointing to one before the first storage unit in the string, in reverse order.

See also
size_storage()
void QString16::swap ( QString16 &  other)
inline

Swaps other with this object. This operation is very fast and never fails.

QString16 QString16::toCaseFolded ( ) &&
nodiscard

Converts the string to case folded and returns the converted string. This method is only called if this string is an rvalue, this occurs when the string is a temporary or has been moved.

Refer to the const reference version of toCaseFolded().

QString16 QString16::toCaseFolded ( ) const &
nodiscard

Returns the case folded equivalent of the string. For most Unicode characters this is the same as toLower().

CFStringRef QString16::toCFString ( ) const

Creates a CFString from a QString. The caller owns the CFString and is responsible for releasing it.

Note
This method is only available on Mac OS X.
template<typename SP = QStringParser>
double QString16::toDouble ( bool *  ok = nullptr) const
inline

Wrapper for QStringParser::toDouble(). In order to use this method in your application include the <QStringParser> header file.

template<typename SP = QStringParser>
float QString16::toFloat ( bool *  ok = nullptr) const
inline

Wrapper for QStringParser::toFloat(). In order to use this method in your application include the <QStringParser> header file.

QString16 QString16::toHtmlEscaped ( ) const

Converts a plain text string to an HTML string with the HTML meta characters <, >, &, and " replaced by the appropriate HTML syntax.

QString16 plain = "#include <QStringView>";
QString16 html = plain.toHtmlEscaped(); // html == "#include &lt;QStringView&gt;"
Note
This method replaces Qt::escape ( const QString & plain )
template<typename R , typename SP = QStringParser>
R QString16::toInteger ( bool *  ok = nullptr,
int  base = 10 
) const
inline

Wrapper for QStringParser::toInteger(). In order to use this method in your application include the <QStringParser> header file.

This method replaces the following set of methods: toInt, toUInt, toLong, toULong, toLongLong, toULongLong, toShort, toUShort. The required data type is passed as the template parameter to this method. The following example shows how to specify long as the type argument.

QString16 str = "45";
long value = str.toInteger<long>(); // value == 45
QByteArray QString16::toLatin1 ( ) const
nodiscard

Returns a Latin-1 representation of the string as a QByteArray. All code points which can not be represented in Latin-1 will be replaced with a question mark.

See also
fromLatin1(), toUtf8()
QString16 QString16::toLower ( ) &&
nodiscard

Converts the string to lowercase and returns the converted string. This method is only called if this string is an rvalue, this occurs when the string is a temporary or has been moved.

Refer to the const reference version of toLower().

QString16 QString16::toLower ( ) const &
nodiscard

Returns a lowercase copy of the string.

QString16 str = "CopperSpice";
str = str.toLower(); // str == "copperspice"

The case conversion will always happen in the 'C' locale. For locale dependent lower casing use QLocale::toLower().

See also
toUpper(), QLocale::toLower()
NSString * QString16::toNSString ( ) const

Creates a NSString from a QString. The NSString is autoreleased.

Note
This method is only available on Mac OS X.
std::wstring QString16::toStdWString ( ) const

Returns this string as an std::wstring encoded in UTF-16.

QString16 QString16::toUpper ( ) &&
nodiscard

Converts the string to uppercase and returns the converted string. This method is only called if this string is an rvalue, this occurs when the string is a temporary or has been moved.

Refer to the const reference version of toUpper().

QString16 QString16::toUpper ( ) const &
nodiscard

Returns an uppercase copy of the string.

QString16 str = "CopperSpice";
str = str.toUpper(); // str == "COPPERSPICE"

The case conversion will always happen in the 'C' locale. For locale dependent upper casing use QLocale::toUpper().

See also
toLower(), QLocale::toUpper()
QByteArray QString16::toUtf8 ( ) const
nodiscard

Returns this string as a QByteArray.

See also
fromUtf8(), toLatin1()
QString16 QString16::trimmed ( ) &&
nodiscard

Trims the string and returns the trimmed string. This method is only called if this string is an rvalue, this occurs when the string is a temporary or has been moved.

Refer to the const reference version of the method trimmed().

QString16 QString16::trimmed ( ) const &
nodiscard

Returns a string that has whitespace removed from the start and the end. Whitespace means any character for which QChar32::isSpace() returns true. This includes the ASCII characters '\t', '\n', '\v', '\f', '\r', and ' '.

QString16 str = " lots\t of\n whitespace\r\n ";
str = str.trimmed(); // str == "lots\t of\n whitespace"

Unlike simplified(), trimmed() leaves internal whitespace alone.

See also
simplified()
void QString16::truncate ( size_type  length)

Removes code points from length to the end of the string. If the specified length is beyond the end of the string, nothing happens. If length is negative it is equivalent to passing zero.

QString16 str = "CopperSpice";
str.truncate(6); // str == "Copper"
See also
chop(), resize(), left()
const uint16_t * QString16::utf16 ( ) const
inline

Returns a pointer to the null terminated data stored in the string. The pointer is valid until the string is modified.

See also
data(), constData(), operator[]()

Friends And Related Function Documentation

bool operator!= ( const char (&)  cString[N],
const QString16 &  str 
)
related

Returns true if the C string cString is not equal to the string str, otherwise returns false.

bool operator!= ( const QString16 &  str,
const char (&)  cString[N] 
)
related

Returns true if the string str is not equal to the C string cString, otherwise returns false.

bool operator!= ( const QString16 &  str1,
const QString16 &  str2 
)
related

Returns true if str1 is not equal to string str2, otherwise returns false.

The comparison is based exclusively on the numeric Unicode values of the code points and is very fast, but may not be what a person would expect.

QString16 operator+ ( const char (&)  cString[N],
const QString16 &  str 
)
related

Returns a string which is the result of concatenating string literal cString and the string str.

QString16 operator+ ( const QString16 &  str,
const char (&)  cString[N] 
)
related

Returns a string which is the result of concatenating str and the string literal cString.

QString16 operator+ ( const QString16 &  str,
QChar32  c 
)
related

Returns a string which is the result of concatenating the string str and the character c.

QString16 operator+ ( const QString16 &  str1,
const QString16 &  str2 
)
related

Returns a string which is the result of concatenating str1 and str2.

QString16 operator+ ( QChar32  c,
const QString16 &  str 
)
related

Returns a string which is the result of concatenating the character c and the string str.

QString16 && operator+ ( QString16 &&  str,
const char (&)  cString[N] 
)
related

Returns a string which is the result of concatenating str and the string literal cString. This method is only called if the string is an rvalue, this occurs when the string is a temporary or has been moved.

QString16 && operator+ ( QString16 &&  str,
QChar32  c 
)
related

Returns a string which is the result of concatenating the string str and the character c. This method is only called if the string is an rvalue, this occurs when the string is a temporary or has been moved.

QString16 && operator+ ( QString16 &&  str1,
const QString16 &  str2 
)
related

Returns a string which is the result of concatenating str1 and str2. This method is only called if str1 is an rvalue, this occurs when the string is a temporary or has been moved.

bool operator< ( const char (&)  cString[N],
const QString16 &  str 
)
related

Returns true if the C string cString is lexically less than string str, otherwise it returns false.

The comparison is based exclusively on the numeric Unicode values of the code points and is very fast, but may not be what a person would expect.

bool operator< ( const QString16 &  str,
const char (&)  cString[N] 
)
related

Returns true if the string str is lexically less than C string cString, otherwise it returns false.

The comparison is based exclusively on the numeric Unicode values of the code points and is very fast, but may not be what a person would expect.

bool operator< ( const QString16 &  str1,
const QString16 &  str2 
)
related

Returns true if the string str1 is lexically less than string str2, otherwise it returns false.

The comparison is based exclusively on the numeric Unicode values of the code points and is very fast, but may not be what a person would expect.

QDataStream & operator<< ( QDataStream stream,
const QString16 &  str 
)
related

Writes str to the stream and returns a reference to the stream.

Refer to Serializing Data Types for additional information.

bool operator<= ( const char (&)  cString[N],
const QString16 &  str 
)
related

Returns true if the C string cString is lexically less than or equal to than string str, otherwise it returns false.

The comparison is based exclusively on the numeric Unicode values of the code points and is very fast, but may not be what a person would expect.

bool operator<= ( const QString16 &  str,
const char (&)  cString[N] 
)
related

Returns true if the string str is lexically less than or equal to than C string cString, otherwise it returns false.

The comparison is based exclusively on the numeric Unicode values of the code points and is very fast, but may not be what a person would expect.

bool operator<= ( const QString16 &  str1,
const QString16 &  str2 
)
related

Returns true if the string str1 is lexically less than or equal to than string str2, otherwise it returns false.

The comparison is based exclusively on the numeric Unicode values of the code points and is very fast, but may not be what a person would expect.

bool operator== ( const char (&)  cString[N],
const QString16 &  str 
)
related

Returns true if the C string cString is equal to string str, otherwise returns false.

bool operator== ( const QString16 &  str,
const char (&)  cString[N] 
)
related

Returns true if string str is equal to the C string cString, otherwise returns false.

bool operator== ( const QString16 &  str1,
const QString16 &  str2 
)
related

Returns true if string str1 is equal to str2, otherwise returns false.

The comparison is based exclusively on the numeric Unicode values of the code points and is very fast, but may not be what a person would expect.

bool operator> ( const char (&)  cString[N],
const QString16 &  str 
)
related

Returns true if the C string cString is lexically greater than string str, otherwise it returns false.

The comparison is based exclusively on the numeric Unicode values of the code points and is very fast, but may not be what a person would expect.

bool operator> ( const QString16 &  str,
const char (&)  cString[N] 
)
related

Returns true if the string str is lexically greater than C string cString, otherwise it returns false.

The comparison is based exclusively on the numeric Unicode values of the code points and is very fast, but may not be what a person would expect.

bool operator> ( const QString16 &  str1,
const QString16 &  str2 
)
related

Returns true if the string str1 is lexically greater than string str2, otherwise it returns false.

The comparison is based exclusively on the numeric Unicode values of the code points and is very fast, but may not be what a person would expect.

bool operator>= ( const char (&)  cString[N],
const QString16 &  str 
)
related

Returns true if the C string cString is lexically greater than or equal to than string str, otherwise it returns false.

The comparison is based exclusively on the numeric Unicode values of the code points and is very fast, but may not be what a person would expect.

bool operator>= ( const QString16 &  str,
const char (&)  cString[N] 
)
related

Returns true if the string str is lexically greater than or equal to than C string cString, otherwise it returns false.

The comparison is based exclusively on the numeric Unicode values of the code points and is very fast, but may not be what a person would expect.

bool operator>= ( const QString16 &  str1,
const QString16 &  str2 
)
related

Returns true if the string str1 is lexically greater than or equal to than string str2, otherwise it returns false.

The comparison is based exclusively on the numeric Unicode values of the code points and is very fast, but may not be what a person would expect.

QDataStream & operator>> ( QDataStream stream,
QString16 &  str 
)
related

Reads from the stream into str and returns a reference to the stream.

Refer to Serializing Data Types for additional information.

void swap ( QString16 &  str1,
QString16 &  str2 
)
related

Swaps string str1 with str2. This operation is very fast and never fails.