The String class is a collection of static functions pertaining to string types.
#include <qx/core/qx-string.h>
|
static bool | isHexNumber (QString hexNum) |
|
static bool | isOnlyNumbers (QString checkStr) |
|
static bool | isValidChecksum (QString checksum, QCryptographicHash::Algorithm hashAlgorithm) |
|
static QString | join (QList< QString > list, QString separator={}, QString prefix={}) |
|
template<typename T, typename F>
requires defines_call_for_s<F, QString, const T&> |
static QString | join (QList< T > list, F &&toStringFunc, QString separator={}, QString prefix={}) |
|
static QString | join (QSet< QString > set, QString separator={}, QString prefix={}) |
|
template<typename T, typename F>
requires defines_call_for_s<F, QString, const T&> |
static QString | join (QSet< T > set, F &&toStringFunc, QString separator={}, QString prefix={}) |
|
static QString | mapArg (QAnyStringView s, const QMap< QString, QString > &map, Qt::CaseSensitivity cs=Qt::CaseSensitive) |
|
static QString | stripToHexOnly (QString string) |
|
static QString | toHeadlineCase (const QString &string) |
|
static QString | trimLeading (const QStringView string) |
|
static QString | trimTrailing (const QStringView string) |
|
◆ isHexNumber()
bool Qx::String::isHexNumber |
( |
QString | hexNum | ) |
|
|
static |
Returns true
if hexNum consists only of numbers and letters A through F (case-insensitive); otherwise returns false
.
◆ isOnlyNumbers()
bool Qx::String::isOnlyNumbers |
( |
QString | checkStr | ) |
|
|
static |
Returns true
if checkStr consists only of numbers; otherwise returns false
.
◆ isValidChecksum()
bool Qx::String::isValidChecksum |
( |
QString | checksum, |
|
|
QCryptographicHash::Algorithm | hashAlgorithm ) |
|
static |
Returns true
if checksum consists only of valid hexadecimal characters and is the exact length required for a hexadecimal string representation of hashAlgorithm; otherwise returns false
.
◆ join() [1/4]
QString Qx::String::join |
( |
QList< QString > | list, |
|
|
QString | separator = {}, |
|
|
QString | prefix = {} ) |
|
static |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Joins all the strings in list with an optional separator and prefix for each element into a single string.
- See also
- QStringList::join().
◆ join() [2/4]
template<typename T, typename F>
requires defines_call_for_s<F, QString, const T&>
static QString Qx::String::join |
( |
QList< T > | list, |
|
|
F && | toStringFunc, |
|
|
QString | separator = {}, |
|
|
QString | prefix = {} ) |
|
inlinestatic |
Joins all arbitrarily typed elements from a list into a single string with optional formatting.
- Parameters
-
[in] | list | The list of elements to join |
[in] | toStringFunc | A function that takes a single element of type T and returns a QString |
[in] | separator | An optional character to place between each element |
[in] | prefix | An optional string to place before each element |
◆ join() [3/4]
QString Qx::String::join |
( |
QSet< QString > | set, |
|
|
QString | separator = {}, |
|
|
QString | prefix = {} ) |
|
static |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Joins all the strings in set with an optional separator and prefix for each element into a single string.
◆ join() [4/4]
template<typename T, typename F>
requires defines_call_for_s<F, QString, const T&>
static QString Qx::String::join |
( |
QSet< T > | set, |
|
|
F && | toStringFunc, |
|
|
QString | separator = {}, |
|
|
QString | prefix = {} ) |
|
inlinestatic |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Joins all arbitrarily typed elements from a set into a single string with optional formatting.
- Parameters
-
[in] | set | The set of elements to join |
[in] | toStringFunc | A function that takes a single element of type T and returns a QString |
[in] | separator | An optional character to place between each element |
[in] | prefix | An optional string to place before each element |
◆ mapArg()
QString Qx::String::mapArg |
( |
QAnyStringView | s, |
|
|
const QMap< QString, QString > & | args, |
|
|
Qt::CaseSensitivity | cs = Qt::CaseSensitive ) |
|
static |
Returns a copy of s with all occurances of each key in args replaced with their corresponding value, using the case sensitivity setting cs.
Similar to the templated version of QString::arg(), this function checks for all replacements in one pass and only performs one heap allocation for the final string, so it should perform much better than chaining QString::replace() multiple times, especially when there is a significant number of replacements.
formatStr.replace(u"phA"_s, u"argA"_s)
.replace(u"phB"_s, u"argB"_s)
.replace(u"phC"_s, u"argC"_s)
...
QString formated = Qx::mapArg(formatStr, {
{u"phA"_s, u"argA"_s},
{u"phB"_s, u"argB"_s},
{u"phC"_s, u"argC"_s},
...
});
◆ stripToHexOnly()
QString Qx::String::stripToHexOnly |
( |
QString | string | ) |
|
|
static |
Returns a copy of string with all non-hexadecimal characters removed.
◆ toHeadlineCase()
QString Qx::String::toHeadlineCase |
( |
const QString & | string | ) |
|
|
static |
Capitalizes the first letter of every word in string, and ensures the rest of the letters are in lower case. This is not the same as Title Case, where some words are never capitalized.
This function considers a 'word' to be distinct after any whitespace occurs.
◆ trimLeading()
QString Qx::String::trimLeading |
( |
const QStringView | string | ) |
|
|
static |
Returns a copy of string with all whitespace at the beginning of the string removed.
Whitespace means any character for which QChar::isSpace() returns true
. This includes the ASCII characters \t
, \n
, \v
, \f
, \r
, and .
Internal whitespace is unaffected.
- See also
- trimTrailing() and QString::trimmed().
◆ trimTrailing()
QString Qx::String::trimTrailing |
( |
const QStringView | string | ) |
|
|
static |
Returns a copy of string with all whitespace at the end of the string removed.
Whitespace means any character for which QChar::isSpace() returns true
. This includes the ASCII characters \t
, \n
, \v
, \f
, \r
, and .
Internal whitespace is unaffected.
- See also
- trimLeading() and QString::trimmed().
The documentation for this class was generated from the following files: