Qt 6.x
The Qt SDK
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
27};
28
29template <typename T> struct QSimpleParsedNumber
30{
32 // When used < 0, -used is how much was used, but it was an error.
34 bool ok() const { return used > 0; }
35};
36
37// API note: this function can't process a number with more than 2.1 billion digits
39qt_asciiToDouble(const char *num, qsizetype numLen,
42 char *buf, qsizetype bufSize,
43 bool &sign, int &length, int &decpt);
44
45[[nodiscard]] QString qulltoBasicLatin(qulonglong l, int base, bool negative);
46[[nodiscard]] QString qulltoa(qulonglong l, int base, const QStringView zero);
47[[nodiscard]] Q_CORE_EXPORT QString qdtoa(qreal d, int *decpt, int *sign);
49 int precision, bool uppercase);
51 int precision, bool uppercase);
52
53[[nodiscard]] constexpr inline bool isZero(double d)
54{
55 return d == 0; // Amusingly, compilers do not grumble.
56}
57
58// Enough space for the digits before the decimal separator:
59[[nodiscard]] inline int wholePartSpace(double d)
60{
61 Q_ASSERT(d >= 0); // caller should call qAbs() if needed
62 // Optimize for numbers between -512k and 512k - otherwise, use the
63 // maximum number of digits in the whole number part of a double:
64 return d > (1 << 19) ? std::numeric_limits<double>::max_exponent10 + 1 : 6;
65}
66
67// Returns code-point of same kind (UCS2 or UCS4) as zero; digit is 0 through 9
68template <typename UcsInt>
69[[nodiscard]] inline UcsInt unicodeForDigit(uint digit, UcsInt zero)
70{
71 // Must match qlocale.cpp's NumberTokenizer's digit-digestion.
72 Q_ASSERT(digit < 10);
73 if (!digit)
74 return zero;
75
76 // See QTBUG-85409: Suzhou's digits are U+3007, U+3021, ..., U+3029
77 if (zero == u'\u3007')
78 return u'\u3020' + digit;
79 // In util/locale_database/ldml.py, LocaleScanner.numericData() asserts no
80 // other number system in CLDR has discontinuous digits.
81
82 return zero + digit;
83}
84
85[[nodiscard]] Q_CORE_EXPORT double qstrntod(const char *s00, qsizetype len,
86 char const **se, bool *ok);
87[[nodiscard]] inline double qstrtod(const char *s00, char const **se, bool *ok)
88{
89 qsizetype len = qsizetype(strlen(s00));
90 return qstrntod(s00, len, se, ok);
91}
92
93[[nodiscard]] Q_AUTOTEST_EXPORT
95[[nodiscard]] QSimpleParsedNumber<qulonglong> qstrntoull(const char *nptr, qsizetype size, int base);
96
98
99#endif
\inmodule QtCore
Definition qbytearray.h:57
\inmodule QtCore
Definition qstringview.h:76
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
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:59
ptrdiff_t qsizetype
Definition qtypes.h:70
unsigned int uint
Definition qtypes.h:29
double qreal
Definition qtypes.h:92
static int sign(int x)