QtlMovie 1.12 (A specialized FFmpeg front-end)
QtlStringUtils.cpp File Reference

Functions

QString qtlHtmlLink (const QString &link, const QString &text)
 Build an HTML string containing a link to a URL. More...
 
QString qtlSecondsToString (int seconds)
 Format a duration into a string. More...
 
QString qtlSizeToString (qlonglong value, int maxDecimalDigits, bool useBinaryUnits, const QString &unitName)
 Format a size into a human-friendly string. More...
 
QString qtlStringSpace (const QString &str, int groupSize, Qt::LayoutDirection direction, const QString &space)
 Insert spaces at regular intervals in a string. More...
 
float qtlToFloat (const QString &str, float def)
 Convert a string into a float. More...
 
int qtlToInt (const QString &str, int def, int min, int max, int base)
 Convert a string into an integer. More...
 
qint64 qtlToInt64 (const QString &str, qint64 def, qint64 min, qint64 max, int base)
 Convert a string into a 64-bit integer. More...
 
quint32 qtlToUInt32 (const QString &str, quint32 def, quint32 min, quint32 max, int base)
 Convert a string into a 32-bit unsigned integer. More...
 
quint64 qtlToUInt64 (const QString &str, quint64 def, quint64 min, quint64 max, int base)
 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...
 

Function Documentation

◆ qtlToInt()

int qtlToInt ( const QString &  str,
int  def = -1,
int  min = 0,
int  max = INT_MAX,
int  base = 10 
)

Convert a string into an integer.

Parameters
[in]strString to convert.
[in]defValue to return if str is not a valid int in the range min to max.
[in]minMinimum allowed value.
[in]maxMaximum allowed value.
[in]baseBase 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.
Returns
The decoded value or def if out of range.

◆ qtlToUInt32()

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.

Parameters
[in]strString to convert.
[in]defValue to return if str is not a valid int in the range min to max.
[in]minMinimum allowed value.
[in]maxMaximum allowed value.
[in]baseBase 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.
Returns
The decoded value or def if out of range.

◆ qtlToInt64()

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.

Parameters
[in]strString to convert.
[in]defValue to return if str is not a valid int in the range min to max.
[in]minMinimum allowed value.
[in]maxMaximum allowed value.
[in]baseBase 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.
Returns
The decoded value or def if out of range.

◆ qtlToUInt64()

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.

Parameters
[in]strString to convert.
[in]defValue to return if str is not a valid int in the range min to max.
[in]minMinimum allowed value.
[in]maxMaximum allowed value.
[in]baseBase 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.
Returns
The decoded value or def if out of range.

◆ qtlToFloat()

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.

Parameters
[in]strString to convert.
[in]defValue to return if str is not a valid float.
Returns
The decoded value or def if invalid.

◆ qtlSecondsToString()

QString qtlSecondsToString ( int  seconds)

Format a duration into a string.

Parameters
[in]secondsDuration in seconds.
Returns
Formatted string.

◆ qtlStringSpace()

QString qtlStringSpace ( const QString &  str,
int  groupSize,
Qt::LayoutDirection  direction = Qt::LeftToRight,
const QString &  space = QStringLiteral(" ") 
)

Insert spaces at regular intervals in a string.

Parameters
[in]strThe string to update.
[in]groupSizeThe number of characters between spaces. If negative or zero, do not insert spaces.
[in]directionThe direction from which the characters are counted.
[in]spaceThe space pattern to use.
Returns
The modified string.

◆ qtlHtmlLink()

QString qtlHtmlLink ( const QString &  link,
const QString &  text = QString() 
)

Build an HTML string containing a link to a URL.

Parameters
[in]linkTarget URL.
[in]textText of the link. If empty (the default), link is also used as text.
Returns
An HTML fragment.

◆ qtlSizeToString()

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.

Parameters
[in]valueThe size value to format.
[in]maxDecimalDigitsMaximum number of decimal digits. Valid values are 0 to 3.
[in]useBinaryUnitsIf 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]unitNameName of the size unit to display. The default is "B" for "byte".
Returns
The formatted string.

◆ qtlToWCharVector()

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.

Parameters
[in]strQt string to convert.
Returns
Corresponding null-terminated vector of wchar_t.