diff options
Diffstat (limited to 'src/corelib/text/qlocale_p.h')
-rw-r--r-- | src/corelib/text/qlocale_p.h | 75 |
1 files changed, 46 insertions, 29 deletions
diff --git a/src/corelib/text/qlocale_p.h b/src/corelib/text/qlocale_p.h index 649f75fbeb..3044d137b9 100644 --- a/src/corelib/text/qlocale_p.h +++ b/src/corelib/text/qlocale_p.h @@ -18,13 +18,16 @@ #include "qlocale.h" -#include <QtCore/private/qglobal_p.h> #include <QtCore/qcalendar.h> #include <QtCore/qlist.h> #include <QtCore/qnumeric.h> +#include <QtCore/private/qnumeric_p.h> #include <QtCore/qstring.h> #include <QtCore/qvariant.h> #include <QtCore/qvarlengtharray.h> +#ifdef Q_OS_WASM +#include <private/qstdweb_p.h> +#endif #include <limits> #include <cmath> @@ -32,6 +35,14 @@ QT_BEGIN_NAMESPACE +template <typename T> struct QSimpleParsedNumber +{ + T result; + // When used < 0, -used is how much was used, but it was an error. + qsizetype used; + bool ok() const { return used > 0; } +}; + template <typename MaskType, uchar Lowest> struct QCharacterSetMatch { static constexpr int MaxRange = std::numeric_limits<MaskType>::digits; @@ -94,7 +105,9 @@ struct QLocaleData; // Subclassed by Android platform plugin: class Q_CORE_EXPORT QSystemLocale { + Q_DISABLE_COPY_MOVE(QSystemLocale) QSystemLocale *next = nullptr; // Maintains a stack. + public: QSystemLocale(); virtual ~QSystemLocale(); @@ -157,7 +170,7 @@ public: StandaloneDayNameShort, // QString, in: int StandaloneDayNameNarrow // QString, in: int }; - virtual QVariant query(QueryType type, QVariant in = QVariant()) const; + virtual QVariant query(QueryType type, QVariant &&in = QVariant()) const; virtual QLocale fallbackLocale() const; inline qsizetype fallbackLocaleIndex() const; @@ -214,6 +227,18 @@ Q_DECLARE_TYPEINFO(QLocaleId, Q_PRIMITIVE_TYPE); using CharBuff = QVarLengthArray<char, 256>; +struct ParsingResult +{ + enum State { // A duplicate of QValidator::State + Invalid, + Intermediate, + Acceptable + }; + + State state = Invalid; + CharBuff buff; +}; + struct QLocaleData { public: @@ -280,36 +305,28 @@ public: unsigned flags = NoFlags) const; // this function is meant to be called with the result of stringToDouble or bytearrayToDouble + // so *ok must have been properly set (if not null) [[nodiscard]] static float convertDoubleToFloat(double d, bool *ok) { - if (qIsInf(d)) - return float(d); - if (std::fabs(d) > (std::numeric_limits<float>::max)()) { - if (ok) - *ok = false; - const float huge = std::numeric_limits<float>::infinity(); - return d < 0 ? -huge : huge; - } - if (d != 0 && float(d) == 0) { - // Values that underflow double already failed. Match them: - if (ok) - *ok = false; - return 0; - } - return float(d); + float result; + bool b = convertDoubleTo<float>(d, &result); + if (ok && *ok) + *ok = b; + return result; } [[nodiscard]] double stringToDouble(QStringView str, bool *ok, QLocale::NumberOptions options) const; - [[nodiscard]] qint64 stringToLongLong(QStringView str, int base, bool *ok, - QLocale::NumberOptions options) const; - [[nodiscard]] quint64 stringToUnsLongLong(QStringView str, int base, bool *ok, - QLocale::NumberOptions options) const; + [[nodiscard]] QSimpleParsedNumber<qint64> + stringToLongLong(QStringView str, int base, QLocale::NumberOptions options) const; + [[nodiscard]] QSimpleParsedNumber<quint64> + stringToUnsLongLong(QStringView str, int base, QLocale::NumberOptions options) const; // this function is used in QIntValidator (QtGui) - [[nodiscard]] Q_CORE_EXPORT static qint64 bytearrayToLongLong(QByteArrayView num, int base, - bool *ok); - [[nodiscard]] static quint64 bytearrayToUnsLongLong(QByteArrayView num, int base, bool *ok); + [[nodiscard]] Q_CORE_EXPORT + static QSimpleParsedNumber<qint64> bytearrayToLongLong(QByteArrayView num, int base); + [[nodiscard]] static QSimpleParsedNumber<quint64> + bytearrayToUnsLongLong(QByteArrayView num, int base); [[nodiscard]] bool numberToCLocale(QStringView s, QLocale::NumberOptions number_options, NumberMode mode, CharBuff *result) const; @@ -361,9 +378,9 @@ public: [[nodiscard]] inline NumericData numericData(NumberMode mode) const; // this function is used in QIntValidator (QtGui) - [[nodiscard]] Q_CORE_EXPORT bool validateChars( - QStringView str, NumberMode numMode, QByteArray *buff, int decDigits = -1, - QLocale::NumberOptions number_options = QLocale::DefaultNumberOptions) const; + [[nodiscard]] Q_CORE_EXPORT ParsingResult + validateChars(QStringView str, NumberMode numMode, int decDigits = -1, + QLocale::NumberOptions number_options = QLocale::DefaultNumberOptions) const; // Access to assorted data members: [[nodiscard]] QLocaleId id() const @@ -465,7 +482,7 @@ public: quint8 m_first_day_of_week : 3; quint8 m_weekend_start : 3; quint8 m_weekend_end : 3; - quint8 m_grouping_top : 2; // Must have this many before the first grouping separator + quint8 m_grouping_top : 2; // Don't group until more significant group has this many digits. quint8 m_grouping_higher : 3; // Number of digits between grouping separators quint8 m_grouping_least : 3; // Number of digits after last grouping separator (before decimal). }; @@ -511,7 +528,7 @@ public: // System locale has an m_data all its own; all others have m_data = locale_data + m_index const QLocaleData *const m_data; QBasicAtomicInt ref; - const qsizetype m_index; + qsizetype m_index; // System locale needs this updated when m_data->id() changes. QLocale::NumberOptions m_numberOptions; static QBasicAtomicInt s_generation; |