Declare some utilities functions for QString. More...
Macros | |
#define | QTL_STRINGIFY(x) |
This macro transforms the value of a macro parameter into the equivalent string. More... | |
Functions | |
template<typename INT > | |
QString | qtlFractionToString (INT numerator, INT divisor=INT(1), int maxDecimalDigits=3) |
Format a fraction numerator / divisor as a packed string. More... | |
QString | qtlHtmlLink (const QString &link, const QString &text=QString()) |
Build an HTML string containing a link to a URL. More... | |
QString | qtlQString (const void *addr, int size) |
Construct a QString from a raw memory area containing UTF-8 characters. More... | |
QString | qtlSecondsToString (int seconds) |
Format a duration into a string. More... | |
QString | qtlSizeToString (qlonglong value, int maxDecimalDigits=3, bool useBinaryUnits=false, const QString &unitName="B") |
Format a size into a human-friendly string. More... | |
QString | qtlStringSpace (const QString &str, int groupSize, Qt::LayoutDirection direction=Qt::LeftToRight, const QString &space=QStringLiteral(" ")) |
Insert spaces at regular intervals in a string. More... | |
float | qtlToFloat (const QString &str, float def=0.0) |
Convert a string into a float. More... | |
int | qtlToInt (const QString &str, int def=-1, int min=0, int max=INT_MAX, int base=10) |
Convert a string into an integer. More... | |
qint64 | qtlToInt64 (const QString &str, qint64 def=-1, qint64 min=0, qint64 max=Q_INT64_C(0x7FFFFFFFFFFFFFFF), int base=10) |
Convert a string into a 64-bit integer. More... | |
quint32 | qtlToUInt32 (const QString &str, quint32 def=0xFFFFFFFFU, quint32 min=0, quint32 max=0xFFFFFFFFU, int base=10) |
Convert a string into a 32-bit unsigned integer. More... | |
quint64 | qtlToUInt64 (const QString &str, quint64 def=Q_UINT64_C(0xFFFFFFFFFFFFFFFF), quint64 min=0, quint64 max=Q_INT64_C(0xFFFFFFFFFFFFFFFF), int base=10) |
Convert a string into a 64-bit unsigned integer. More... | |
QVector< wchar_t > | qtlToWCharVector (const QString &str) |
Convert a QString into a null-terminated vector of wchar_t. More... | |
Declare some utilities functions for QString.
Qtl, Qt utility library.
#define QTL_STRINGIFY | ( | x | ) |
This macro transforms the value of a macro parameter into the equivalent string.
This is a very specific macro. It is typically used only inside the definition of another macro. It is similar to the # token in the preprocessor but has a slightly different effect. The # token transforms the text of a macro parameter into a string while QTL_STRINGIFY transforms the value of a macro parameter into a string, after all preprocessing substitutions.
The following example illustrates the difference between the # token and V_SYS_STRINGIFY:
This will print:
|
inline |
Construct a QString from a raw memory area containing UTF-8 characters.
[in] | addr | Starting address. |
[in] | size | Size in bytes. |
int qtlToInt | ( | const QString & | str, |
int | def = -1 , |
||
int | min = 0 , |
||
int | max = INT_MAX , |
||
int | base = 10 |
||
) |
Convert a string into an integer.
[in] | str | String to convert. |
[in] | def | Value to return if str is not a valid int in the range min to max. |
[in] | min | Minimum allowed value. |
[in] | max | Maximum allowed value. |
[in] | base | Base for conversion, 10 by default, must be between 2 and 36, or 0. If base is 0, the C language convention is used: If the string begins with "0x", base 16 is used; if the string begins with "0", base 8 is used; otherwise, base 10 is used. |
quint32 qtlToUInt32 | ( | const QString & | str, |
quint32 | def = 0xFFFFFFFFU , |
||
quint32 | min = 0 , |
||
quint32 | max = 0xFFFFFFFFU , |
||
int | base = 10 |
||
) |
Convert a string into a 32-bit unsigned integer.
[in] | str | String to convert. |
[in] | def | Value to return if str is not a valid int in the range min to max. |
[in] | min | Minimum allowed value. |
[in] | max | Maximum allowed value. |
[in] | base | Base for conversion, 10 by default, must be between 2 and 36, or 0. If base is 0, the C language convention is used: If the string begins with "0x", base 16 is used; if the string begins with "0", base 8 is used; otherwise, base 10 is used. |
qint64 qtlToInt64 | ( | const QString & | str, |
qint64 | def = -1 , |
||
qint64 | min = 0 , |
||
qint64 | max = Q_INT64_C(0x7FFFFFFFFFFFFFFF) , |
||
int | base = 10 |
||
) |
Convert a string into a 64-bit integer.
[in] | str | String to convert. |
[in] | def | Value to return if str is not a valid int in the range min to max. |
[in] | min | Minimum allowed value. |
[in] | max | Maximum allowed value. |
[in] | base | Base for conversion, 10 by default, must be between 2 and 36, or 0. If base is 0, the C language convention is used: If the string begins with "0x", base 16 is used; if the string begins with "0", base 8 is used; otherwise, base 10 is used. |
quint64 qtlToUInt64 | ( | const QString & | str, |
quint64 | def = Q_UINT64_C(0xFFFFFFFFFFFFFFFF) , |
||
quint64 | min = 0 , |
||
quint64 | max = Q_INT64_C(0xFFFFFFFFFFFFFFFF) , |
||
int | base = 10 |
||
) |
Convert a string into a 64-bit unsigned integer.
[in] | str | String to convert. |
[in] | def | Value to return if str is not a valid int in the range min to max. |
[in] | min | Minimum allowed value. |
[in] | max | Maximum allowed value. |
[in] | base | Base for conversion, 10 by default, must be between 2 and 36, or 0. If base is 0, the C language convention is used: If the string begins with "0x", base 16 is used; if the string begins with "0", base 8 is used; otherwise, base 10 is used. |
float qtlToFloat | ( | const QString & | str, |
float | def = 0.0 |
||
) |
Convert a string into a float.
Syntax like "x/y" and "x:y" are interpreted as rational numbers.
[in] | str | String to convert. |
[in] | def | Value to return if str is not a valid float. |
QString qtlStringSpace | ( | const QString & | str, |
int | groupSize, | ||
Qt::LayoutDirection | direction = Qt::LeftToRight , |
||
const QString & | space = QStringLiteral(" ") |
||
) |
Insert spaces at regular intervals in a string.
[in] | str | The string to update. |
[in] | groupSize | The number of characters between spaces. If negative or zero, do not insert spaces. |
[in] | direction | The direction from which the characters are counted. |
[in] | space | The space pattern to use. |
QString qtlSecondsToString | ( | int | seconds | ) |
Format a duration into a string.
[in] | seconds | Duration in seconds. |
QString qtlSizeToString | ( | qlonglong | value, |
int | maxDecimalDigits = 3 , |
||
bool | useBinaryUnits = false , |
||
const QString & | unitName = "B" |
||
) |
Format a size into a human-friendly string.
The resulting string is approximated into the closest "big unit" such as "kB", MB", etc. The default unit is "B" for bytes but it is replaceable.
[in] | value | The size value to format. |
[in] | maxDecimalDigits | Maximum number of decimal digits. Valid values are 0 to 3. |
[in] | useBinaryUnits | If true, use "binary" units, meaning chunks of 1024 units instead of 1000. The abbreviations are updated accordingly. For instance, "1 MB" for "MegaByte" becomes "0.954 MiB" for "MibiByte". The default is false, meaning use standard decimal units or chunks of 1000 units. |
[in] | unitName | Name of the size unit to display. The default is "B" for "byte". |
QString qtlFractionToString | ( | INT | numerator, |
INT | divisor = INT(1) , |
||
int | maxDecimalDigits = 3 |
||
) |
Format a fraction numerator / divisor as a packed string.
INT | Any numerical type. |
[in] | numerator | Numerator of the fraction. |
[in] | divisor | Divisor of the fraction. |
[in] | maxDecimalDigits | Maximum number of decimal digits. Valid values are 0 to 3. In the result, useless trailing zeroes and decimal dot are removed. |
QString qtlHtmlLink | ( | const QString & | link, |
const QString & | text = QString() |
||
) |
Build an HTML string containing a link to a URL.
[in] | link | Target URL. |
[in] | text | Text of the link. If empty (the default), link is also used as text. |
QVector<wchar_t> qtlToWCharVector | ( | const QString & | str | ) |
Convert a QString into a null-terminated vector of wchar_t.
Can be useful to call native C functions using wide characters.
[in] | str | Qt string to convert. |