diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2019-01-23 16:31:35 +0100 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2019-02-21 15:08:10 +0000 |
commit | 783953f09dcfe9c58dc991394535ba07dabe2560 (patch) | |
tree | 447479aaacb43e90c2551d79561f6c88e56a9b08 /src/corelib/tools/qlocale.cpp | |
parent | ae9be1a63d7b579fb5bb8b4bf903f1a3efe7168f (diff) |
Add conversion to and from long and ulong
This implements conversion parity with QString, which can convert to
and from long and unsigned long.
The implementation simply forwards to existing long long overloads or
uses the existing helpers, so just as for the conversion to/from int
or short, no additional test cases were added.
Change-Id: I37ef06d9ce4d80d98bd72720353996bac723e09c
Fixes: QTBUG-782
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/corelib/tools/qlocale.cpp')
-rw-r--r-- | src/corelib/tools/qlocale.cpp | 126 |
1 files changed, 126 insertions, 0 deletions
diff --git a/src/corelib/tools/qlocale.cpp b/src/corelib/tools/qlocale.cpp index b3fb079342..ebb6c97975 100644 --- a/src/corelib/tools/qlocale.cpp +++ b/src/corelib/tools/qlocale.cpp @@ -1333,6 +1333,48 @@ uint QLocale::toUInt(const QString &s, bool *ok) const } /*! + Returns the long int represented by the localized string \a s. + + If the conversion fails the function returns 0. + + 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. + + This function ignores leading and trailing whitespace. + + \sa toInt(), toULong(), toDouble(), toString() + + \since 5.13 + */ + + +long QLocale::toLong(const QString &s, bool *ok) const +{ + return toIntegral_helper<long>(d, s, ok); +} + +/*! + Returns the unsigned long int represented by the localized + string \a s. + + If the conversion fails the function returns 0. + + 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. + + This function ignores leading and trailing whitespace. + + \sa toLong(), toInt(), toDouble(), toString() + + \since 5.13 +*/ + +ulong QLocale::toULong(const QString &s, bool *ok) const +{ + return toIntegral_helper<ulong>(d, s, ok); +} + +/*! Returns the long long int represented by the localized string \a s. If the conversion fails the function returns 0. @@ -1500,6 +1542,48 @@ uint QLocale::toUInt(const QStringRef &s, bool *ok) const } /*! + Returns the long int represented by the localized string \a s. + + If the conversion fails the function returns 0. + + 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. + + This function ignores leading and trailing whitespace. + + \sa toInt(), toULong(), toDouble(), toString() + + \since 5.13 + */ + + +long QLocale::toLong(const QStringRef &s, bool *ok) const +{ + return toIntegral_helper<long>(d, s, ok); +} + +/*! + Returns the unsigned long int represented by the localized + string \a s. + + If the conversion fails the function returns 0. + + 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. + + This function ignores leading and trailing whitespace. + + \sa toLong(), toInt(), toDouble(), toString() + + \since 5.13 + */ + +ulong QLocale::toULong(const QStringRef &s, bool *ok) const +{ + return toIntegral_helper<ulong>(d, s, ok); +} + +/*! Returns the long long int represented by the localized string \a s. If the conversion fails the function returns 0. @@ -1676,6 +1760,48 @@ uint QLocale::toUInt(QStringView s, bool *ok) const } /*! + Returns the long int represented by the localized string \a s. + + If the conversion fails the function returns 0. + + 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. + + This function ignores leading and trailing whitespace. + + \sa toInt(), toULong(), toDouble(), toString() + + \since 5.13 + */ + + +long QLocale::toLong(QStringView s, bool *ok) const +{ + return toIntegral_helper<long>(d, s, ok); +} + +/*! + Returns the unsigned long int represented by the localized + string \a s. + + If the conversion fails the function returns 0. + + 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. + + This function ignores leading and trailing whitespace. + + \sa toLong(), toInt(), toDouble(), toString() + + \since 5.13 + */ + +ulong QLocale::toULong(QStringView s, bool *ok) const +{ + return toIntegral_helper<ulong>(d, s, ok); +} + +/*! Returns the long long int represented by the localized string \a s. If the conversion fails, the function returns 0. |