Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qdoublescanprint_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// Qt-Security score:critical reason:data-parser
4
5#ifndef QDOUBLESCANPRINT_P_H
6#define QDOUBLESCANPRINT_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists for the convenience
13// of internal files. This header file may change from version to version
14// without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <private/qglobal_p.h>
20
21#if defined(Q_CC_MSVC) && (defined(QT_BOOTSTRAPPED) || defined(QT_NO_DOUBLECONVERSION))
22# include <stdio.h>
23# include <locale.h>
24
25QT_BEGIN_NAMESPACE
26
27// We can always use _sscanf_l and _snprintf_l on MSVC as those were introduced in 2005.
28
29// MSVC doesn't document what it will do with a NULL locale passed to _sscanf_l or _snprintf_l.
30// The documentation for _create_locale() does not formally document "C" to be valid, but an example
31// code snippet in the same documentation shows it.
32
33struct QCLocaleT {
34 QCLocaleT() : locale(_create_locale(LC_ALL, "C"))
35 {
36 }
37
38 ~QCLocaleT()
39 {
40 _free_locale(locale);
41 }
42
43 const _locale_t locale;
44};
45
46# define QT_CLOCALE_HOLDER Q_GLOBAL_STATIC(QCLocaleT, cLocaleT)
47# define QT_CLOCALE cLocaleT()->locale
48
49inline int qDoubleSscanf(const char *buf, _locale_t locale, const char *format, double *d,
50 int *processed)
51{
52 return _sscanf_l(buf, format, locale, d, processed);
53}
54
55inline int qDoubleSnprintf(char *buf, size_t buflen, _locale_t locale, const char *format, double d)
56{
57 return _snprintf_l(buf, buflen, format, locale, d);
58}
59
60QT_END_NAMESPACE
61
62#elif defined(QT_BOOTSTRAPPED)
63# include <stdio.h>
64
65QT_BEGIN_NAMESPACE
66
67// When bootstrapping we don't have libdouble-conversion available, yet. We can also not use locale
68// aware snprintf and sscanf variants in the general case because those are only available on select
69// platforms. We can use the regular snprintf and sscanf because we don't do setlocale(3) when
70// bootstrapping and the locale is always "C" then.
71
72# define QT_CLOCALE_HOLDER
73# define QT_CLOCALE 0
74
75inline int qDoubleSscanf(const char *buf, int, const char *format, double *d, int *processed)
76{
77 return sscanf(buf, format, d, processed);
78}
79inline int qDoubleSnprintf(char *buf, size_t buflen, int, const char *format, double d)
80{
81 return snprintf(buf, buflen, format, d);
82}
83
84QT_END_NAMESPACE
85
86#else // !QT_BOOTSTRAPPED && (!Q_CC_MSVC || !QT_NO_DOUBLECONVERSION)
87# ifdef QT_NO_DOUBLECONVERSION
88# include <stdio.h>
89# include <xlocale.h>
90
91QT_BEGIN_NAMESPACE
92
93// OS X and FreeBSD both treat NULL as the "C" locale for snprintf_l and sscanf_l.
94// When other implementations with different behavior show up, we'll have to do newlocale(3) and
95// freelocale(3) here. The arguments to those will depend on what the other implementations will
96// offer. OS X and FreeBSD again interpret a locale name of NULL as "C", but "C" itself is not
97// documented as valid locale name. Mind that the names of the LC_* constants differ between e.g.
98// BSD variants and linux.
99
100# define QT_CLOCALE_HOLDER
101# define QT_CLOCALE NULL
102
103inline int qDoubleSscanf(const char *buf, locale_t locale, const char *format, double *d,
104 int *processed)
105{
106 return sscanf_l(buf, locale, format, d, processed);
107}
108inline int qDoubleSnprintf(char *buf, size_t buflen, locale_t locale, const char *format, double d)
109{
110 return snprintf_l(buf, buflen, locale, format, d);
111}
112
113QT_END_NAMESPACE
114
115# else // !QT_NO_DOUBLECONVERSION
116# include <double-conversion/double-conversion.h>
117# define QT_CLOCALE_HOLDER
118# endif // QT_NO_DOUBLECONVERSION
119#endif // QT_BOOTSTRAPPED
120
121#endif // QDOUBLESCANPRINT_P_H
#define QT_CLOCALE_HOLDER
static T dtoString(double d, QLocaleData::DoubleForm form, int precision, bool uppercase)
#define LLONG_MAX
static Q_ALWAYS_INLINE void qulltoString_helper(qulonglong number, int base, Char *&p)
static auto scanPrefix(const char *p, const char *stop, int base)
static constexpr int digits(int number)
#define SMALL_BASE_LOOP(b)
#define ULLONG_MAX
static bool isDigitForBase(char d, int base)
QSimpleParsedNumber< qlonglong > qstrntoll(const char *begin, qsizetype size, int base)
#define BIG_BASE_LOOP(b)
static QLocaleData::DoubleForm resolveFormat(int precision, int decpt, qsizetype length)
#define LLONG_MIN
QString qdtoa(qreal d, int *decpt, int *sign)
StrayCharacterMode
@ TrailingJunkAllowed
Q_CORE_EXPORT double qstrntod(const char *s00, qsizetype len, char const **se, bool *ok)
QSimpleParsedNumber< double > qt_asciiToDouble(const char *num, qsizetype numLen, StrayCharacterMode strayCharMode=TrailingJunkProhibited)
QByteArray qdtoAscii(double d, QLocaleData::DoubleForm form, int precision, bool uppercase)
char * qulltoa2(char *p, qulonglong n, int base)
QString qdtoBasicLatin(double d, QLocaleData::DoubleForm form, int precision, bool uppercase)
QString qulltoa(qulonglong l, int base, const QStringView zero)
QSimpleParsedNumber< qulonglong > qstrntoull(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)
QString qulltoBasicLatin(qulonglong l, int base, bool negative)
#define QStringLiteral(str)
Definition qstring.h:1826
@ DFSignificantDigits
Definition qlocale_p.h:261