diff options
Diffstat (limited to 'src/corelib/tools/qlocale_p.h')
-rw-r--r-- | src/corelib/tools/qlocale_p.h | 90 |
1 files changed, 57 insertions, 33 deletions
diff --git a/src/corelib/tools/qlocale_p.h b/src/corelib/tools/qlocale_p.h index b3fd7a96b8..f95edf4d14 100644 --- a/src/corelib/tools/qlocale_p.h +++ b/src/corelib/tools/qlocale_p.h @@ -1,31 +1,38 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ +** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2016 Intel Corporation. +** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtCore module of the Qt Toolkit. ** -** $QT_BEGIN_LICENSE:LGPL21$ +** $QT_BEGIN_LICENSE:LGPL$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. ** -** As a special exception, The Qt Company gives you certain additional -** rights. These rights are described in The Qt Company LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. ** ** $QT_END_LICENSE$ ** @@ -165,6 +172,17 @@ public: QLocale::Country country); static const QLocaleData *c(); + // Maximum number of significant digits needed to represent a double. + // We cannot use std::numeric_limits here without constexpr. + static const int DoubleMantissaBits = 53; + static const int Log10_2_100000 = 30103; // log10(2) * 100000 + // same as C++11 std::numeric_limits<T>::max_digits10 + static const int DoubleMaxSignificant = (DoubleMantissaBits * Log10_2_100000) / 100000 + 2; + + // Maximum number of digits before decimal point to represent a double + // Same as std::numeric_limits<double>::max_exponent10 + 1 + static const int DoubleMaxDigitsBeforeDecimal = 309; + enum DoubleForm { DFExponent = 0, DFDecimal, @@ -184,14 +202,10 @@ public: ShowBase = 0x80, UppercaseBase = 0x100, + ZeroPadExponent = 0x200, ForcePoint = Alternate }; - enum GroupSeparatorMode { - FailOnGroupSeparators, - ParseGroupSeparators - }; - enum NumberMode { IntegerMode, DoubleStandardMode, DoubleScientificMode }; typedef QVarLengthArray<char, 256> CharBuff; @@ -239,24 +253,26 @@ public: return float(d); } - double stringToDouble(const QChar *begin, int len, bool *ok, GroupSeparatorMode group_sep_mode) const; - qint64 stringToLongLong(const QChar *begin, int len, int base, bool *ok, GroupSeparatorMode group_sep_mode) const; - quint64 stringToUnsLongLong(const QChar *begin, int len, int base, bool *ok, GroupSeparatorMode group_sep_mode) const; + double stringToDouble(const QChar *begin, int len, bool *ok, + QLocale::NumberOptions number_options) const; + qint64 stringToLongLong(const QChar *begin, int len, int base, bool *ok, + QLocale::NumberOptions number_options) const; + quint64 stringToUnsLongLong(const QChar *begin, int len, int base, bool *ok, + QLocale::NumberOptions number_options) const; // these functions are used in QIntValidator (QtGui) Q_CORE_EXPORT static double bytearrayToDouble(const char *num, bool *ok, bool *overflow = 0); Q_CORE_EXPORT static qint64 bytearrayToLongLong(const char *num, int base, bool *ok, bool *overflow = 0); Q_CORE_EXPORT static quint64 bytearrayToUnsLongLong(const char *num, int base, bool *ok); - bool numberToCLocale(const QChar *str, int len, - GroupSeparatorMode group_sep_mode, - CharBuff *result) const; + bool numberToCLocale(const QChar *str, int len, QLocale::NumberOptions number_options, + CharBuff *result) const; inline char digitToCLocale(QChar c) const; // this function is used in QIntValidator (QtGui) - Q_CORE_EXPORT bool validateChars(const QString &str, NumberMode numMode, - QByteArray *buff, int decDigits = -1, - bool rejectGroupSeparators = false) const; + Q_CORE_EXPORT bool validateChars( + const QString &str, NumberMode numMode, QByteArray *buff, int decDigits = -1, + QLocale::NumberOptions number_options = QLocale::DefaultNumberOptions) const; public: quint16 m_language_id, m_script_id, m_country_id; @@ -304,7 +320,9 @@ public: class Q_CORE_EXPORT QLocalePrivate { public: - static QLocalePrivate *create(const QLocaleData *data, int numberOptions = 0) + static QLocalePrivate *create( + const QLocaleData *data, + QLocale::NumberOptions numberOptions = QLocale::DefaultNumberOptions) { QLocalePrivate *retval = new QLocalePrivate; retval->m_data = data; @@ -335,9 +353,15 @@ public: static QString languageToCode(QLocale::Language language); static QString scriptToCode(QLocale::Script script); static QString countryToCode(QLocale::Country country); - static QLocale::Language codeToLanguage(const QString &code); - static QLocale::Script codeToScript(const QString &code); - static QLocale::Country codeToCountry(const QString &code); + static QLocale::Language codeToLanguage(const QChar *code, int len) Q_DECL_NOTHROW; + static QLocale::Language codeToLanguage(const QString &code) Q_DECL_NOTHROW { return codeToLanguage(code.data(), code.size()); } + static QLocale::Language codeToLanguage(const QStringRef &code) Q_DECL_NOTHROW { return codeToLanguage(code.data(), code.size()); } + static QLocale::Script codeToScript(const QChar *code, int len) Q_DECL_NOTHROW; + static QLocale::Script codeToScript(const QString &code) Q_DECL_NOTHROW { return codeToScript(code.data(), code.size()); } + static QLocale::Script codeToScript(const QStringRef &code) Q_DECL_NOTHROW { return codeToScript(code.data(), code.size()); } + static QLocale::Country codeToCountry(const QChar *code, int len) Q_DECL_NOTHROW; + static QLocale::Country codeToCountry(const QString &code) Q_DECL_NOTHROW { return codeToCountry(code.data(), code.size()); } + static QLocale::Country codeToCountry(const QStringRef &code) Q_DECL_NOTHROW { return codeToCountry(code.data(), code.size()); } static void getLangAndCountry(const QString &name, QLocale::Language &lang, QLocale::Script &script, QLocale::Country &cntry); @@ -351,7 +375,7 @@ public: const QLocaleData *m_data; QBasicAtomicInt ref; - quint16 m_numberOptions; + QLocale::NumberOptions m_numberOptions; }; template <> |