File indexing completed on 2025-01-18 09:55:28
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028 #ifndef DOUBLE_CONVERSION_UTILS_H_
0029 #define DOUBLE_CONVERSION_UTILS_H_
0030
0031
0032
0033
0034 #include <cstdlib>
0035 #include <cstring>
0036
0037
0038 #if __cplusplus >= 201103L
0039 #define DOUBLE_CONVERSION_NULLPTR nullptr
0040 #else
0041 #define DOUBLE_CONVERSION_NULLPTR NULL
0042 #endif
0043
0044 #include <cassert>
0045 #ifndef DOUBLE_CONVERSION_ASSERT
0046 #define DOUBLE_CONVERSION_ASSERT(condition) \
0047 assert(condition)
0048 #endif
0049 #if defined(DOUBLE_CONVERSION_NON_PREFIXED_MACROS) && !defined(ASSERT)
0050 #define ASSERT DOUBLE_CONVERSION_ASSERT
0051 #endif
0052
0053 #ifndef DOUBLE_CONVERSION_UNIMPLEMENTED
0054 #define DOUBLE_CONVERSION_UNIMPLEMENTED() (abort())
0055 #endif
0056 #if defined(DOUBLE_CONVERSION_NON_PREFIXED_MACROS) && !defined(UNIMPLEMENTED)
0057 #define UNIMPLEMENTED DOUBLE_CONVERSION_UNIMPLEMENTED
0058 #endif
0059
0060 #ifndef DOUBLE_CONVERSION_NO_RETURN
0061 #ifdef _MSC_VER
0062 #define DOUBLE_CONVERSION_NO_RETURN __declspec(noreturn)
0063 #else
0064 #define DOUBLE_CONVERSION_NO_RETURN __attribute__((noreturn))
0065 #endif
0066 #endif
0067 #if defined(DOUBLE_CONVERSION_NON_PREFIXED_MACROS) && !defined(NO_RETURN)
0068 #define NO_RETURN DOUBLE_CONVERSION_NO_RETURN
0069 #endif
0070
0071 #ifndef DOUBLE_CONVERSION_UNREACHABLE
0072 #ifdef _MSC_VER
0073 void DOUBLE_CONVERSION_NO_RETURN abort_noreturn();
0074 inline void abort_noreturn() { abort(); }
0075 #define DOUBLE_CONVERSION_UNREACHABLE() (abort_noreturn())
0076 #else
0077 #define DOUBLE_CONVERSION_UNREACHABLE() (abort())
0078 #endif
0079 #endif
0080 #if defined(DOUBLE_CONVERSION_NON_PREFIXED_MACROS) && !defined(UNREACHABLE)
0081 #define UNREACHABLE DOUBLE_CONVERSION_UNREACHABLE
0082 #endif
0083
0084
0085
0086 #ifdef __has_attribute
0087 # define DOUBLE_CONVERSION_HAS_ATTRIBUTE(x) __has_attribute(x)
0088 #else
0089 # define DOUBLE_CONVERSION_HAS_ATTRIBUTE(x) 0
0090 #endif
0091
0092 #ifndef DOUBLE_CONVERSION_UNUSED
0093 #if DOUBLE_CONVERSION_HAS_ATTRIBUTE(unused)
0094 #define DOUBLE_CONVERSION_UNUSED __attribute__((unused))
0095 #else
0096 #define DOUBLE_CONVERSION_UNUSED
0097 #endif
0098 #endif
0099 #if defined(DOUBLE_CONVERSION_NON_PREFIXED_MACROS) && !defined(UNUSED)
0100 #define UNUSED DOUBLE_CONVERSION_UNUSED
0101 #endif
0102
0103 #if DOUBLE_CONVERSION_HAS_ATTRIBUTE(uninitialized)
0104 #define DOUBLE_CONVERSION_STACK_UNINITIALIZED __attribute__((uninitialized))
0105 #else
0106 #define DOUBLE_CONVERSION_STACK_UNINITIALIZED
0107 #endif
0108 #if defined(DOUBLE_CONVERSION_NON_PREFIXED_MACROS) && !defined(STACK_UNINITIALIZED)
0109 #define STACK_UNINITIALIZED DOUBLE_CONVERSION_STACK_UNINITIALIZED
0110 #endif
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138 #if defined(_M_X64) || defined(__x86_64__) || \
0139 defined(__ARMEL__) || defined(__avr32__) || defined(_M_ARM) || defined(_M_ARM64) || \
0140 defined(__hppa__) || defined(__ia64__) || \
0141 defined(__mips__) || \
0142 defined(__loongarch__) || \
0143 defined(__nios2__) || defined(__ghs) || \
0144 defined(__powerpc__) || defined(__ppc__) || defined(__ppc64__) || \
0145 defined(_POWER) || defined(_ARCH_PPC) || defined(_ARCH_PPC64) || \
0146 defined(__sparc__) || defined(__sparc) || defined(__s390__) || \
0147 defined(__SH4__) || defined(__alpha__) || \
0148 defined(_MIPS_ARCH_MIPS32R2) || defined(__ARMEB__) ||\
0149 defined(__AARCH64EL__) || defined(__aarch64__) || defined(__AARCH64EB__) || \
0150 defined(__riscv) || defined(__e2k__) || \
0151 defined(__or1k__) || defined(__arc__) || defined(__ARC64__) || \
0152 defined(__microblaze__) || defined(__XTENSA__) || \
0153 defined(__EMSCRIPTEN__) || defined(__wasm32__)
0154 #define DOUBLE_CONVERSION_CORRECT_DOUBLE_OPERATIONS 1
0155 #elif defined(__mc68000__) || \
0156 defined(__pnacl__) || defined(__native_client__)
0157 #undef DOUBLE_CONVERSION_CORRECT_DOUBLE_OPERATIONS
0158 #elif defined(_M_IX86) || defined(__i386__) || defined(__i386)
0159 #if defined(_WIN32)
0160
0161 #define DOUBLE_CONVERSION_CORRECT_DOUBLE_OPERATIONS 1
0162 #else
0163 #undef DOUBLE_CONVERSION_CORRECT_DOUBLE_OPERATIONS
0164 #endif
0165 #else
0166 #error Target architecture was not detected as supported by Double-Conversion.
0167 #endif
0168 #if defined(DOUBLE_CONVERSION_NON_PREFIXED_MACROS) && !defined(CORRECT_DOUBLE_OPERATIONS)
0169 #define CORRECT_DOUBLE_OPERATIONS DOUBLE_CONVERSION_CORRECT_DOUBLE_OPERATIONS
0170 #endif
0171
0172 #if defined(_WIN32) && !defined(__MINGW32__)
0173
0174 typedef signed char int8_t;
0175 typedef unsigned char uint8_t;
0176 typedef short int16_t;
0177 typedef unsigned short uint16_t;
0178 typedef int int32_t;
0179 typedef unsigned int uint32_t;
0180 typedef __int64 int64_t;
0181 typedef unsigned __int64 uint64_t;
0182
0183
0184 #else
0185
0186 #include <stdint.h>
0187
0188 #endif
0189
0190 typedef uint16_t uc16;
0191
0192
0193
0194
0195 #define DOUBLE_CONVERSION_UINT64_2PART_C(a, b) (((static_cast<uint64_t>(a) << 32) + 0x##b##u))
0196 #if defined(DOUBLE_CONVERSION_NON_PREFIXED_MACROS) && !defined(UINT64_2PART_C)
0197 #define UINT64_2PART_C DOUBLE_CONVERSION_UINT64_2PART_C
0198 #endif
0199
0200
0201
0202
0203
0204 #ifndef DOUBLE_CONVERSION_ARRAY_SIZE
0205 #define DOUBLE_CONVERSION_ARRAY_SIZE(a) \
0206 ((sizeof(a) / sizeof(*(a))) / \
0207 static_cast<size_t>(!(sizeof(a) % sizeof(*(a)))))
0208 #endif
0209 #if defined(DOUBLE_CONVERSION_NON_PREFIXED_MACROS) && !defined(ARRAY_SIZE)
0210 #define ARRAY_SIZE DOUBLE_CONVERSION_ARRAY_SIZE
0211 #endif
0212
0213
0214
0215 #ifndef DOUBLE_CONVERSION_DISALLOW_COPY_AND_ASSIGN
0216 #define DOUBLE_CONVERSION_DISALLOW_COPY_AND_ASSIGN(TypeName) \
0217 TypeName(const TypeName&); \
0218 void operator=(const TypeName&)
0219 #endif
0220 #if defined(DOUBLE_CONVERSION_NON_PREFIXED_MACROS) && !defined(DC_DISALLOW_COPY_AND_ASSIGN)
0221 #define DC_DISALLOW_COPY_AND_ASSIGN DOUBLE_CONVERSION_DISALLOW_COPY_AND_ASSIGN
0222 #endif
0223
0224
0225
0226
0227
0228
0229
0230 #ifndef DOUBLE_CONVERSION_DISALLOW_IMPLICIT_CONSTRUCTORS
0231 #define DOUBLE_CONVERSION_DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \
0232 TypeName(); \
0233 DOUBLE_CONVERSION_DISALLOW_COPY_AND_ASSIGN(TypeName)
0234 #endif
0235 #if defined(DOUBLE_CONVERSION_NON_PREFIXED_MACROS) && !defined(DC_DISALLOW_IMPLICIT_CONSTRUCTORS)
0236 #define DC_DISALLOW_IMPLICIT_CONSTRUCTORS DOUBLE_CONVERSION_DISALLOW_IMPLICIT_CONSTRUCTORS
0237 #endif
0238
0239 namespace double_conversion {
0240
0241 inline int StrLength(const char* string) {
0242 size_t length = strlen(string);
0243 DOUBLE_CONVERSION_ASSERT(length == static_cast<size_t>(static_cast<int>(length)));
0244 return static_cast<int>(length);
0245 }
0246
0247
0248 template <typename T>
0249 class Vector {
0250 public:
0251 Vector() : start_(DOUBLE_CONVERSION_NULLPTR), length_(0) {}
0252 Vector(T* data, int len) : start_(data), length_(len) {
0253 DOUBLE_CONVERSION_ASSERT(len == 0 || (len > 0 && data != DOUBLE_CONVERSION_NULLPTR));
0254 }
0255
0256
0257
0258 Vector<T> SubVector(int from, int to) {
0259 DOUBLE_CONVERSION_ASSERT(to <= length_);
0260 DOUBLE_CONVERSION_ASSERT(from < to);
0261 DOUBLE_CONVERSION_ASSERT(0 <= from);
0262 return Vector<T>(start() + from, to - from);
0263 }
0264
0265
0266 int length() const { return length_; }
0267
0268
0269 bool is_empty() const { return length_ == 0; }
0270
0271
0272 T* start() const { return start_; }
0273
0274
0275 T& operator[](int index) const {
0276 DOUBLE_CONVERSION_ASSERT(0 <= index && index < length_);
0277 return start_[index];
0278 }
0279
0280 T& first() { return start_[0]; }
0281
0282 T& last() { return start_[length_ - 1]; }
0283
0284 void pop_back() {
0285 DOUBLE_CONVERSION_ASSERT(!is_empty());
0286 --length_;
0287 }
0288
0289 private:
0290 T* start_;
0291 int length_;
0292 };
0293
0294
0295
0296
0297
0298 class StringBuilder {
0299 public:
0300 StringBuilder(char* buffer, int buffer_size)
0301 : buffer_(buffer, buffer_size), position_(0) { }
0302
0303 ~StringBuilder() { if (!is_finalized()) Finalize(); }
0304
0305 int size() const { return buffer_.length(); }
0306
0307
0308 int position() const {
0309 DOUBLE_CONVERSION_ASSERT(!is_finalized());
0310 return position_;
0311 }
0312
0313
0314 void Reset() { position_ = 0; }
0315
0316
0317
0318
0319 void AddCharacter(char c) {
0320 DOUBLE_CONVERSION_ASSERT(c != '\0');
0321 DOUBLE_CONVERSION_ASSERT(!is_finalized() && position_ < buffer_.length());
0322 buffer_[position_++] = c;
0323 }
0324
0325
0326
0327 void AddString(const char* s) {
0328 AddSubstring(s, StrLength(s));
0329 }
0330
0331
0332
0333 void AddSubstring(const char* s, int n) {
0334 DOUBLE_CONVERSION_ASSERT(!is_finalized() && position_ + n < buffer_.length());
0335 DOUBLE_CONVERSION_ASSERT(static_cast<size_t>(n) <= strlen(s));
0336 memmove(&buffer_[position_], s, static_cast<size_t>(n));
0337 position_ += n;
0338 }
0339
0340
0341
0342
0343 void AddPadding(char c, int count) {
0344 for (int i = 0; i < count; i++) {
0345 AddCharacter(c);
0346 }
0347 }
0348
0349
0350 char* Finalize() {
0351 DOUBLE_CONVERSION_ASSERT(!is_finalized() && position_ < buffer_.length());
0352 buffer_[position_] = '\0';
0353
0354
0355 DOUBLE_CONVERSION_ASSERT(strlen(buffer_.start()) == static_cast<size_t>(position_));
0356 position_ = -1;
0357 DOUBLE_CONVERSION_ASSERT(is_finalized());
0358 return buffer_.start();
0359 }
0360
0361 private:
0362 Vector<char> buffer_;
0363 int position_;
0364
0365 bool is_finalized() const { return position_ < 0; }
0366
0367 DOUBLE_CONVERSION_DISALLOW_IMPLICIT_CONSTRUCTORS(StringBuilder);
0368 };
0369
0370
0371
0372
0373
0374
0375
0376
0377
0378
0379
0380
0381
0382
0383
0384
0385
0386
0387
0388
0389
0390
0391
0392
0393
0394 template <class Dest, class Source>
0395 Dest BitCast(const Source& source) {
0396
0397
0398 #if __cplusplus >= 201103L
0399 static_assert(sizeof(Dest) == sizeof(Source),
0400 "source and destination size mismatch");
0401 #else
0402 DOUBLE_CONVERSION_UNUSED
0403 typedef char VerifySizesAreEqual[sizeof(Dest) == sizeof(Source) ? 1 : -1];
0404 #endif
0405
0406 Dest dest;
0407 memmove(&dest, &source, sizeof(dest));
0408 return dest;
0409 }
0410
0411 template <class Dest, class Source>
0412 Dest BitCast(Source* source) {
0413 return BitCast<Dest>(reinterpret_cast<uintptr_t>(source));
0414 }
0415
0416 }
0417
0418 #endif