Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qlocale_tools_p.h
Go to the documentation of this file.
1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QLOCALE_TOOLS_P_H
5#define QLOCALE_TOOLS_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists for the convenience
12// of internal files. This header file may change from version to version
13// without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include "qlocale_p.h"
19#include "qstring.h"
20
22
28
29// API note: this function can't process a number with more than 2.1 billion digits
30[[nodiscard]] QSimpleParsedNumber<double>
31qt_asciiToDouble(const char *num, qsizetype numLen,
34 char *buf, qsizetype bufSize,
35 bool &sign, int &length, int &decpt);
36
37[[nodiscard]] QString qulltoBasicLatin(qulonglong l, int base, bool negative);
38[[nodiscard]] QString qulltoa(qulonglong l, int base, const QStringView zero);
39[[nodiscard]] Q_CORE_EXPORT QString qdtoa(qreal d, int *decpt, int *sign);
41 int precision, bool uppercase);
43 int precision, bool uppercase);
44
45[[nodiscard]] constexpr inline bool isZero(double d)
46{
47 return d == 0; // Amusingly, compilers do not grumble.
48}
49
50// Enough space for the digits before the decimal separator:
51[[nodiscard]] inline int wholePartSpace(double d)
52{
53 Q_ASSERT(d >= 0); // caller should call qAbs() if needed
54 // Optimize for numbers between -512k and 512k - otherwise, use the
55 // maximum number of digits in the whole number part of a double:
56 return d > (1 << 19) ? std::numeric_limits<double>::max_exponent10 + 1 : 6;
57}
58
59// Returns code-point of same kind (UCS2 or UCS4) as zero; digit is 0 through 9
60template <typename UcsInt>
61[[nodiscard]] inline UcsInt unicodeForDigit(uint digit, UcsInt zero)
62{
63 // Must match qlocale.cpp's NumberTokenizer's digit-digestion.
64 Q_ASSERT(digit < 10);
65 if (!digit)
66 return zero;
67
68 // See QTBUG-85409: Suzhou's digits are U+3007, U+3021, ..., U+3029
69 if (zero == u'\u3007')
70 return u'\u3020' + digit;
71 // In util/locale_database/ldml.py, LocaleScanner.numericData() asserts no
72 // other number system in CLDR has discontinuous digits.
73
74 return zero + digit;
75}
76
77[[nodiscard]] Q_CORE_EXPORT double qstrntod(const char *s00, qsizetype len,
78 char const **se, bool *ok);
79[[nodiscard]] inline double qstrtod(const char *s00, char const **se, bool *ok)
80{
81 qsizetype len = qsizetype(strlen(s00));
82 return qstrntod(s00, len, se, ok);
83}
84
85[[nodiscard]] Q_AUTOTEST_EXPORT
86QSimpleParsedNumber<qlonglong> qstrntoll(const char *nptr, qsizetype size, int base);
87[[nodiscard]] QSimpleParsedNumber<qulonglong> qstrntoull(const char *nptr, qsizetype size, int base);
88
90
91#endif
\inmodule QtCore
Definition qbytearray.h:57
\inmodule QtCore
Definition qstringview.h:78
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
Combined button and popup list for selecting options.
StrayCharacterMode
@ TrailingJunkAllowed
@ TrailingJunkProhibited
@ WhitespacesAllowed
Q_CORE_EXPORT QString qdtoa(qreal d, int *decpt, int *sign)
double qstrtod(const char *s00, char const **se, bool *ok)
QSimpleParsedNumber< double > qt_asciiToDouble(const char *num, qsizetype numLen, StrayCharacterMode strayCharMode=TrailingJunkProhibited)
constexpr bool isZero(double d)
QByteArray qdtoAscii(double d, QLocaleData::DoubleForm form, int precision, bool uppercase)
int wholePartSpace(double d)
QString qdtoBasicLatin(double d, QLocaleData::DoubleForm form, int precision, bool uppercase)
UcsInt unicodeForDigit(uint digit, UcsInt zero)
QString qulltoa(qulonglong l, int base, const QStringView zero)
QSimpleParsedNumber< qulonglong > qstrntoull(const char *nptr, qsizetype size, int base)
Q_AUTOTEST_EXPORT QSimpleParsedNumber< qlonglong > qstrntoll(const char *nptr, qsizetype size, int base)
void qt_doubleToAscii(double d, QLocaleData::DoubleForm form, int precision, char *buf, qsizetype bufSize, bool &sign, int &length, int &decpt)
Q_CORE_EXPORT double qstrntod(const char *s00, qsizetype len, char const **se, bool *ok)
QString qulltoBasicLatin(qulonglong l, int base, bool negative)
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLenum GLuint GLenum GLsizei length
GLenum GLuint GLenum GLsizei const GLchar * buf
GLsizei bufSize
GLenum GLsizei len
GLuint num
GLenum GLint GLint * precision
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
#define zero
#define Q_AUTOTEST_EXPORT
quint64 qulonglong
Definition qtypes.h:64
ptrdiff_t qsizetype
Definition qtypes.h:165
unsigned int uint
Definition qtypes.h:34
double qreal
Definition qtypes.h:187
static const uint base
Definition qurlidna.cpp:20
static int sign(int x)