summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qstring.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/tools/qstring.cpp')
-rw-r--r--src/corelib/tools/qstring.cpp109
1 files changed, 59 insertions, 50 deletions
diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp
index b6731cffcd..d3a6851e2c 100644
--- a/src/corelib/tools/qstring.cpp
+++ b/src/corelib/tools/qstring.cpp
@@ -7104,8 +7104,8 @@ QString QString::vasprintf(const char *cformat, va_list ap)
base, which is 10 by default and must be between 2 and 36, or 0.
Returns 0 if the conversion fails.
- If a conversion error occurs, *\a{ok} is set to \c false; otherwise
- *\a{ok} is set to \c true.
+ If \a ok is not \c nullptr, failure is reported by setting *\a{ok}
+ to \c false, and success by setting *\a{ok} to \c true.
If \a 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",
@@ -7146,8 +7146,8 @@ qlonglong QString::toIntegral_helper(const QChar *data, int len, bool *ok, int b
base, which is 10 by default and must be between 2 and 36, or 0.
Returns 0 if the conversion fails.
- If a conversion error occurs, *\a{ok} is set to \c false; otherwise
- *\a{ok} is set to \c true.
+ If \a ok is not \c nullptr, failure is reported by setting *\a{ok}
+ to \c false, and success by setting *\a{ok} to \c true.
If \a 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",
@@ -7190,8 +7190,8 @@ qulonglong QString::toIntegral_helper(const QChar *data, uint len, bool *ok, int
base, which is 10 by default and must be between 2 and 36, or 0.
Returns 0 if the conversion fails.
- If a conversion error occurs, *\a{ok} is set to \c false; otherwise
- *\a{ok} is set to \c true.
+ If \a ok is not \c nullptr, failure is reported by setting *\a{ok}
+ to \c false, and success by setting *\a{ok} to \c true.
If \a 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",
@@ -7221,8 +7221,8 @@ long QString::toLong(bool *ok, int base) const
base, which is 10 by default and must be between 2 and 36, or 0.
Returns 0 if the conversion fails.
- If a conversion error occurs, *\a{ok} is set to \c false; otherwise
- *\a{ok} is set to \c true.
+ If \a ok is not \c nullptr, failure is reported by setting *\a{ok}
+ to \c false, and success by setting *\a{ok} to \c true.
If \a 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",
@@ -7251,8 +7251,8 @@ ulong QString::toULong(bool *ok, int base) const
base, which is 10 by default and must be between 2 and 36, or 0.
Returns 0 if the conversion fails.
- If a conversion error occurs, *\a{ok} is set to \c false; otherwise
- *\a{ok} is set to \c true.
+ If \a ok is not \c nullptr, failure is reported by setting *\a{ok}
+ to \c false, and success by setting *\a{ok} to \c true.
If \a 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",
@@ -7280,8 +7280,8 @@ int QString::toInt(bool *ok, int base) const
base, which is 10 by default and must be between 2 and 36, or 0.
Returns 0 if the conversion fails.
- If a conversion error occurs, *\a{ok} is set to \c false; otherwise
- *\a{ok} is set to \c true.
+ If \a ok is not \c nullptr, failure is reported by setting *\a{ok}
+ to \c false, and success by setting *\a{ok} to \c true.
If \a 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",
@@ -7309,8 +7309,8 @@ uint QString::toUInt(bool *ok, int base) const
base, which is 10 by default and must be between 2 and 36, or 0.
Returns 0 if the conversion fails.
- If a conversion error occurs, *\a{ok} is set to \c false; otherwise
- *\a{ok} is set to \c true.
+ If \a ok is not \c nullptr, failure is reported by setting *\a{ok}
+ to \c false, and success by setting *\a{ok} to \c true.
If \a 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",
@@ -7338,8 +7338,8 @@ short QString::toShort(bool *ok, int base) const
base, which is 10 by default and must be between 2 and 36, or 0.
Returns 0 if the conversion fails.
- If a conversion error occurs, *\a{ok} is set to \c false; otherwise
- *\a{ok} is set to \c true.
+ If \a ok is not \c nullptr, failure is reported by setting *\a{ok}
+ to \c false, and success by setting *\a{ok} to \c true.
If \a 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",
@@ -7368,8 +7368,8 @@ ushort QString::toUShort(bool *ok, int base) const
Returns 0.0 if the conversion fails.
- If a conversion error occurs, \c{*}\a{ok} is set to \c false;
- otherwise \c{*}\a{ok} is set to \c true.
+ If \a ok is not \c nullptr, failure is reported by setting *\a{ok}
+ to \c false, and success by setting *\a{ok} to \c true.
\snippet qstring/main.cpp 66
@@ -7404,21 +7404,30 @@ double QString::toDouble(bool *ok) const
/*!
Returns the string converted to a \c float value.
- If a conversion error occurs, *\a{ok} is set to \c false; otherwise
- *\a{ok} is set to \c true. Returns 0.0 if the conversion fails.
+ Returns 0.0 if the conversion fails.
- This function ignores leading and trailing whitespace.
+ If \a ok is not \c nullptr, failure is reported by setting *\a{ok}
+ to \c false, and success by setting *\a{ok} to \c true.
+
+ \warning The QString content may only contain valid numerical characters
+ which includes the plus/minus sign, the characters g and e used in scientific
+ notation, and the decimal point. Including the unit or additional characters
+ leads to a conversion error.
The string conversion will always happen in the 'C' locale. For locale
dependent conversion use QLocale::toFloat()
+ For historical reasons, this function does not handle
+ thousands group separators. If you need to convert such numbers,
+ use QLocale::toFloat().
+
Example:
\snippet qstring/main.cpp 71
This function ignores leading and trailing whitespace.
- \sa number(), toDouble(), toInt(), QLocale::toFloat()
+ \sa number(), toDouble(), toInt(), QLocale::toFloat(), trimmed()
*/
float QString::toFloat(bool *ok) const
@@ -7611,13 +7620,12 @@ QString QString::number(qulonglong n, int base)
QString QString::number(double n, char f, int prec)
{
QLocaleData::DoubleForm form = QLocaleData::DFDecimal;
- uint flags = 0;
+ uint flags = QLocaleData::ZeroPadExponent;
if (qIsUpper(f))
- flags = QLocaleData::CapitalEorX;
- f = qToLower(f);
+ flags |= QLocaleData::CapitalEorX;
- switch (f) {
+ switch (qToLower(f)) {
case 'f':
form = QLocaleData::DFDecimal;
break;
@@ -8676,14 +8684,13 @@ QString QString::arg(double a, int fieldWidth, char fmt, int prec, QChar fillCha
unsigned flags = QLocaleData::NoFlags;
if (fillChar == QLatin1Char('0'))
- flags = QLocaleData::ZeroPadded;
+ flags |= QLocaleData::ZeroPadded;
if (qIsUpper(fmt))
flags |= QLocaleData::CapitalEorX;
- fmt = qToLower(fmt);
QLocaleData::DoubleForm form = QLocaleData::DFDecimal;
- switch (fmt) {
+ switch (qToLower(fmt)) {
case 'f':
form = QLocaleData::DFDecimal;
break;
@@ -8702,7 +8709,7 @@ QString QString::arg(double a, int fieldWidth, char fmt, int prec, QChar fillCha
QString arg;
if (d.occurrences > d.locale_occurrences)
- arg = QLocaleData::c()->doubleToString(a, prec, form, fieldWidth, flags);
+ arg = QLocaleData::c()->doubleToString(a, prec, form, fieldWidth, flags | QLocaleData::ZeroPadExponent);
QString locale_arg;
if (d.locale_occurrences > 0) {
@@ -11772,8 +11779,8 @@ QStringRef QStringRef::trimmed() const
base, which is 10 by default and must be between 2 and 36, or 0.
Returns 0 if the conversion fails.
- If a conversion error occurs, *\a{ok} is set to \c false; otherwise
- *\a{ok} is set to \c true.
+ If \a ok is not \c nullptr, failure is reported by setting *\a{ok}
+ to \c false, and success by setting *\a{ok} to \c true.
If \a 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",
@@ -11797,8 +11804,8 @@ qint64 QStringRef::toLongLong(bool *ok, int base) const
base, which is 10 by default and must be between 2 and 36, or 0.
Returns 0 if the conversion fails.
- If a conversion error occurs, *\a{ok} is set to \c false; otherwise
- *\a{ok} is set to \c true.
+ If \a ok is not \c nullptr, failure is reported by setting *\a{ok}
+ to \c false, and success by setting *\a{ok} to \c true.
If \a 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",
@@ -11824,8 +11831,8 @@ quint64 QStringRef::toULongLong(bool *ok, int base) const
base, which is 10 by default and must be between 2 and 36, or 0.
Returns 0 if the conversion fails.
- If a conversion error occurs, *\a{ok} is set to \c false; otherwise
- *\a{ok} is set to \c true.
+ If \a ok is not \c nullptr, failure is reported by setting *\a{ok}
+ to \c false, and success by setting *\a{ok} to \c true.
If \a 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",
@@ -11851,8 +11858,8 @@ long QStringRef::toLong(bool *ok, int base) const
base, which is 10 by default and must be between 2 and 36, or 0.
Returns 0 if the conversion fails.
- If a conversion error occurs, *\a{ok} is set to \c false; otherwise
- *\a{ok} is set to \c true.
+ If \a ok is not \c nullptr, failure is reported by setting *\a{ok}
+ to \c false, and success by setting *\a{ok} to \c true.
If \a 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",
@@ -11877,8 +11884,8 @@ ulong QStringRef::toULong(bool *ok, int base) const
base, which is 10 by default and must be between 2 and 36, or 0.
Returns 0 if the conversion fails.
- If a conversion error occurs, *\a{ok} is set to \c false; otherwise
- *\a{ok} is set to \c true.
+ If \a ok is not \c nullptr, failure is reported by setting *\a{ok}
+ to \c false, and success by setting *\a{ok} to \c true.
If \a 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",
@@ -11902,8 +11909,8 @@ int QStringRef::toInt(bool *ok, int base) const
base, which is 10 by default and must be between 2 and 36, or 0.
Returns 0 if the conversion fails.
- If a conversion error occurs, *\a{ok} is set to \c false; otherwise
- *\a{ok} is set to \c true.
+ If \a ok is not \c nullptr, failure is reported by setting *\a{ok}
+ to \c false, and success by setting *\a{ok} to \c true.
If \a 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",
@@ -11927,8 +11934,8 @@ uint QStringRef::toUInt(bool *ok, int base) const
base, which is 10 by default and must be between 2 and 36, or 0.
Returns 0 if the conversion fails.
- If a conversion error occurs, *\a{ok} is set to \c false; otherwise
- *\a{ok} is set to \c true.
+ If \a ok is not \c nullptr, failure is reported by setting *\a{ok}
+ to \c false, and success by setting *\a{ok} to \c true.
If \a 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",
@@ -11952,8 +11959,8 @@ short QStringRef::toShort(bool *ok, int base) const
base, which is 10 by default and must be between 2 and 36, or 0.
Returns 0 if the conversion fails.
- If a conversion error occurs, *\a{ok} is set to \c false; otherwise
- *\a{ok} is set to \c true.
+ If \a ok is not \c nullptr, failure is reported by setting *\a{ok}
+ to \c false, and success by setting *\a{ok} to \c true.
If \a 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",
@@ -11978,8 +11985,8 @@ ushort QStringRef::toUShort(bool *ok, int base) const
Returns 0.0 if the conversion fails.
- If a conversion error occurs, \c{*}\a{ok} is set to \c false;
- otherwise \c{*}\a{ok} is set to \c true.
+ If \a ok is not \c nullptr, failure is reported by setting *\a{ok}
+ to \c false, and success by setting *\a{ok} to \c true.
The string conversion will always happen in the 'C' locale. For locale
dependent conversion use QLocale::toDouble()
@@ -12001,8 +12008,10 @@ double QStringRef::toDouble(bool *ok) const
/*!
Returns the string converted to a \c float value.
- If a conversion error occurs, *\a{ok} is set to \c false; otherwise
- *\a{ok} is set to \c true. Returns 0.0 if the conversion fails.
+ Returns 0.0 if the conversion fails.
+
+ If \a ok is not \c nullptr, failure is reported by setting *\a{ok}
+ to \c false, and success by setting *\a{ok} to \c true.
The string conversion will always happen in the 'C' locale. For locale
dependent conversion use QLocale::toFloat()