ycpp 0.1.0__cp315-cp315-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (142) hide show
  1. ycpp/__init__.py +110 -0
  2. ycpp/_array.py +318 -0
  3. ycpp/_awareness.py +268 -0
  4. ycpp/_doc.py +718 -0
  5. ycpp/_event.py +188 -0
  6. ycpp/_id_map.py +620 -0
  7. ycpp/_map.py +267 -0
  8. ycpp/_provider.py +180 -0
  9. ycpp/_snapshot.py +28 -0
  10. ycpp/_sticky_index.py +59 -0
  11. ycpp/_stream.py +91 -0
  12. ycpp/_sync.py +192 -0
  13. ycpp/_text.py +239 -0
  14. ycpp/_transaction.py +287 -0
  15. ycpp/_typed.py +122 -0
  16. ycpp/_undo.py +201 -0
  17. ycpp/_update.py +18 -0
  18. ycpp/_xml.py +452 -0
  19. ycpp/_ycpp.cp315-win_amd64.lib +0 -0
  20. ycpp/_ycpp.cp315-win_amd64.pyd +0 -0
  21. ycpp-0.1.0.data/headers/fast_float/ascii_number.h +766 -0
  22. ycpp-0.1.0.data/headers/fast_float/bigint.h +638 -0
  23. ycpp-0.1.0.data/headers/fast_float/constexpr_feature_detect.h +53 -0
  24. ycpp-0.1.0.data/headers/fast_float/decimal_to_binary.h +212 -0
  25. ycpp-0.1.0.data/headers/fast_float/digit_comparison.h +455 -0
  26. ycpp-0.1.0.data/headers/fast_float/fast_float.h +91 -0
  27. ycpp-0.1.0.data/headers/fast_float/fast_table.h +708 -0
  28. ycpp-0.1.0.data/headers/fast_float/float_common.h +1432 -0
  29. ycpp-0.1.0.data/headers/fast_float/parse_number.h +488 -0
  30. ycpp-0.1.0.data/headers/xsimd/arch/common/xsimd_common_arithmetic.hpp +267 -0
  31. ycpp-0.1.0.data/headers/xsimd/arch/common/xsimd_common_bit.hpp +230 -0
  32. ycpp-0.1.0.data/headers/xsimd/arch/common/xsimd_common_cast.hpp +43 -0
  33. ycpp-0.1.0.data/headers/xsimd/arch/common/xsimd_common_complex.hpp +112 -0
  34. ycpp-0.1.0.data/headers/xsimd/arch/common/xsimd_common_details.hpp +386 -0
  35. ycpp-0.1.0.data/headers/xsimd/arch/common/xsimd_common_logical.hpp +240 -0
  36. ycpp-0.1.0.data/headers/xsimd/arch/common/xsimd_common_math.hpp +2601 -0
  37. ycpp-0.1.0.data/headers/xsimd/arch/common/xsimd_common_memory.hpp +1006 -0
  38. ycpp-0.1.0.data/headers/xsimd/arch/common/xsimd_common_rounding.hpp +72 -0
  39. ycpp-0.1.0.data/headers/xsimd/arch/common/xsimd_common_swizzle.hpp +260 -0
  40. ycpp-0.1.0.data/headers/xsimd/arch/common/xsimd_common_trigo.hpp +996 -0
  41. ycpp-0.1.0.data/headers/xsimd/arch/utils/shifts.hpp +82 -0
  42. ycpp-0.1.0.data/headers/xsimd/arch/xsimd_avx.hpp +2111 -0
  43. ycpp-0.1.0.data/headers/xsimd/arch/xsimd_avx2.hpp +1591 -0
  44. ycpp-0.1.0.data/headers/xsimd/arch/xsimd_avx512bw.hpp +724 -0
  45. ycpp-0.1.0.data/headers/xsimd/arch/xsimd_avx512cd.hpp +28 -0
  46. ycpp-0.1.0.data/headers/xsimd/arch/xsimd_avx512dq.hpp +270 -0
  47. ycpp-0.1.0.data/headers/xsimd/arch/xsimd_avx512er.hpp +17 -0
  48. ycpp-0.1.0.data/headers/xsimd/arch/xsimd_avx512f.hpp +2919 -0
  49. ycpp-0.1.0.data/headers/xsimd/arch/xsimd_avx512ifma.hpp +17 -0
  50. ycpp-0.1.0.data/headers/xsimd/arch/xsimd_avx512pf.hpp +17 -0
  51. ycpp-0.1.0.data/headers/xsimd/arch/xsimd_avx512vbmi.hpp +76 -0
  52. ycpp-0.1.0.data/headers/xsimd/arch/xsimd_avx512vbmi2.hpp +130 -0
  53. ycpp-0.1.0.data/headers/xsimd/arch/xsimd_avx512vnni_avx512bw.hpp +17 -0
  54. ycpp-0.1.0.data/headers/xsimd/arch/xsimd_avx512vnni_avx512vbmi2.hpp +17 -0
  55. ycpp-0.1.0.data/headers/xsimd/arch/xsimd_avxvnni.hpp +17 -0
  56. ycpp-0.1.0.data/headers/xsimd/arch/xsimd_common.hpp +26 -0
  57. ycpp-0.1.0.data/headers/xsimd/arch/xsimd_common_fwd.hpp +127 -0
  58. ycpp-0.1.0.data/headers/xsimd/arch/xsimd_constants.hpp +393 -0
  59. ycpp-0.1.0.data/headers/xsimd/arch/xsimd_emulated.hpp +787 -0
  60. ycpp-0.1.0.data/headers/xsimd/arch/xsimd_fma3_avx.hpp +93 -0
  61. ycpp-0.1.0.data/headers/xsimd/arch/xsimd_fma3_avx2.hpp +46 -0
  62. ycpp-0.1.0.data/headers/xsimd/arch/xsimd_fma3_sse.hpp +97 -0
  63. ycpp-0.1.0.data/headers/xsimd/arch/xsimd_fma4.hpp +92 -0
  64. ycpp-0.1.0.data/headers/xsimd/arch/xsimd_i8mm_neon64.hpp +17 -0
  65. ycpp-0.1.0.data/headers/xsimd/arch/xsimd_isa.hpp +146 -0
  66. ycpp-0.1.0.data/headers/xsimd/arch/xsimd_neon.hpp +3580 -0
  67. ycpp-0.1.0.data/headers/xsimd/arch/xsimd_neon64.hpp +1614 -0
  68. ycpp-0.1.0.data/headers/xsimd/arch/xsimd_rvv.hpp +1515 -0
  69. ycpp-0.1.0.data/headers/xsimd/arch/xsimd_scalar.hpp +1210 -0
  70. ycpp-0.1.0.data/headers/xsimd/arch/xsimd_sse2.hpp +2333 -0
  71. ycpp-0.1.0.data/headers/xsimd/arch/xsimd_sse3.hpp +66 -0
  72. ycpp-0.1.0.data/headers/xsimd/arch/xsimd_sse4_1.hpp +510 -0
  73. ycpp-0.1.0.data/headers/xsimd/arch/xsimd_sse4_2.hpp +44 -0
  74. ycpp-0.1.0.data/headers/xsimd/arch/xsimd_ssse3.hpp +186 -0
  75. ycpp-0.1.0.data/headers/xsimd/arch/xsimd_sve.hpp +1186 -0
  76. ycpp-0.1.0.data/headers/xsimd/arch/xsimd_vsx.hpp +916 -0
  77. ycpp-0.1.0.data/headers/xsimd/arch/xsimd_vxe.hpp +787 -0
  78. ycpp-0.1.0.data/headers/xsimd/arch/xsimd_wasm.hpp +1819 -0
  79. ycpp-0.1.0.data/headers/xsimd/config/xsimd_arch.hpp +242 -0
  80. ycpp-0.1.0.data/headers/xsimd/config/xsimd_config.hpp +620 -0
  81. ycpp-0.1.0.data/headers/xsimd/config/xsimd_cpu_features.hpp +50 -0
  82. ycpp-0.1.0.data/headers/xsimd/config/xsimd_cpu_features_arm.hpp +132 -0
  83. ycpp-0.1.0.data/headers/xsimd/config/xsimd_cpu_features_ppc.hpp +54 -0
  84. ycpp-0.1.0.data/headers/xsimd/config/xsimd_cpu_features_riscv.hpp +95 -0
  85. ycpp-0.1.0.data/headers/xsimd/config/xsimd_cpu_features_s390x.hpp +56 -0
  86. ycpp-0.1.0.data/headers/xsimd/config/xsimd_cpu_features_x86.hpp +1044 -0
  87. ycpp-0.1.0.data/headers/xsimd/config/xsimd_cpuid.hpp +144 -0
  88. ycpp-0.1.0.data/headers/xsimd/config/xsimd_getauxval.hpp +159 -0
  89. ycpp-0.1.0.data/headers/xsimd/config/xsimd_macros.hpp +76 -0
  90. ycpp-0.1.0.data/headers/xsimd/math/xsimd_rem_pio2.hpp +707 -0
  91. ycpp-0.1.0.data/headers/xsimd/memory/xsimd_aligned_allocator.hpp +349 -0
  92. ycpp-0.1.0.data/headers/xsimd/memory/xsimd_alignment.hpp +102 -0
  93. ycpp-0.1.0.data/headers/xsimd/types/xsimd_all_registers.hpp +57 -0
  94. ycpp-0.1.0.data/headers/xsimd/types/xsimd_api.hpp +3106 -0
  95. ycpp-0.1.0.data/headers/xsimd/types/xsimd_avx2_register.hpp +44 -0
  96. ycpp-0.1.0.data/headers/xsimd/types/xsimd_avx512bw_register.hpp +51 -0
  97. ycpp-0.1.0.data/headers/xsimd/types/xsimd_avx512cd_register.hpp +51 -0
  98. ycpp-0.1.0.data/headers/xsimd/types/xsimd_avx512dq_register.hpp +51 -0
  99. ycpp-0.1.0.data/headers/xsimd/types/xsimd_avx512er_register.hpp +51 -0
  100. ycpp-0.1.0.data/headers/xsimd/types/xsimd_avx512f_register.hpp +77 -0
  101. ycpp-0.1.0.data/headers/xsimd/types/xsimd_avx512ifma_register.hpp +51 -0
  102. ycpp-0.1.0.data/headers/xsimd/types/xsimd_avx512pf_register.hpp +51 -0
  103. ycpp-0.1.0.data/headers/xsimd/types/xsimd_avx512vbmi2_register.hpp +51 -0
  104. ycpp-0.1.0.data/headers/xsimd/types/xsimd_avx512vbmi_register.hpp +51 -0
  105. ycpp-0.1.0.data/headers/xsimd/types/xsimd_avx512vnni_avx512bw_register.hpp +54 -0
  106. ycpp-0.1.0.data/headers/xsimd/types/xsimd_avx512vnni_avx512vbmi2_register.hpp +53 -0
  107. ycpp-0.1.0.data/headers/xsimd/types/xsimd_avx_register.hpp +64 -0
  108. ycpp-0.1.0.data/headers/xsimd/types/xsimd_avxvnni_register.hpp +44 -0
  109. ycpp-0.1.0.data/headers/xsimd/types/xsimd_batch.hpp +1665 -0
  110. ycpp-0.1.0.data/headers/xsimd/types/xsimd_batch_constant.hpp +571 -0
  111. ycpp-0.1.0.data/headers/xsimd/types/xsimd_batch_fwd.hpp +41 -0
  112. ycpp-0.1.0.data/headers/xsimd/types/xsimd_common_arch.hpp +49 -0
  113. ycpp-0.1.0.data/headers/xsimd/types/xsimd_emulated_register.hpp +80 -0
  114. ycpp-0.1.0.data/headers/xsimd/types/xsimd_fma3_avx2_register.hpp +50 -0
  115. ycpp-0.1.0.data/headers/xsimd/types/xsimd_fma3_avx_register.hpp +50 -0
  116. ycpp-0.1.0.data/headers/xsimd/types/xsimd_fma3_sse_register.hpp +50 -0
  117. ycpp-0.1.0.data/headers/xsimd/types/xsimd_fma4_register.hpp +50 -0
  118. ycpp-0.1.0.data/headers/xsimd/types/xsimd_i8mm_neon64_register.hpp +55 -0
  119. ycpp-0.1.0.data/headers/xsimd/types/xsimd_neon64_register.hpp +55 -0
  120. ycpp-0.1.0.data/headers/xsimd/types/xsimd_neon_register.hpp +130 -0
  121. ycpp-0.1.0.data/headers/xsimd/types/xsimd_register.hpp +96 -0
  122. ycpp-0.1.0.data/headers/xsimd/types/xsimd_rvv_register.hpp +491 -0
  123. ycpp-0.1.0.data/headers/xsimd/types/xsimd_sse2_register.hpp +59 -0
  124. ycpp-0.1.0.data/headers/xsimd/types/xsimd_sse3_register.hpp +49 -0
  125. ycpp-0.1.0.data/headers/xsimd/types/xsimd_sse4_1_register.hpp +48 -0
  126. ycpp-0.1.0.data/headers/xsimd/types/xsimd_sse4_2_register.hpp +48 -0
  127. ycpp-0.1.0.data/headers/xsimd/types/xsimd_ssse3_register.hpp +48 -0
  128. ycpp-0.1.0.data/headers/xsimd/types/xsimd_sve_register.hpp +216 -0
  129. ycpp-0.1.0.data/headers/xsimd/types/xsimd_traits.hpp +408 -0
  130. ycpp-0.1.0.data/headers/xsimd/types/xsimd_utils.hpp +462 -0
  131. ycpp-0.1.0.data/headers/xsimd/types/xsimd_vsx_register.hpp +77 -0
  132. ycpp-0.1.0.data/headers/xsimd/types/xsimd_vxe_register.hpp +86 -0
  133. ycpp-0.1.0.data/headers/xsimd/types/xsimd_wasm_register.hpp +59 -0
  134. ycpp-0.1.0.data/headers/xsimd/utils/bits.hpp +122 -0
  135. ycpp-0.1.0.data/headers/xsimd/utils/xsimd_type_traits.hpp +145 -0
  136. ycpp-0.1.0.data/headers/xsimd/xsimd.hpp +43 -0
  137. ycpp-0.1.0.dist-info/DELVEWHEEL +2 -0
  138. ycpp-0.1.0.dist-info/METADATA +15 -0
  139. ycpp-0.1.0.dist-info/RECORD +142 -0
  140. ycpp-0.1.0.dist-info/WHEEL +4 -0
  141. ycpp.libs/msvcp140-a4c2229bdc2a2a630acdc095b4d86008.dll +0 -0
  142. ycpp.libs/msvcp140_1-226498d4bfcb4f07974757b596ebec45.dll +0 -0
@@ -0,0 +1,766 @@
1
+ #ifndef FASTFLOAT_ASCII_NUMBER_H
2
+ #define FASTFLOAT_ASCII_NUMBER_H
3
+
4
+ #include <cctype>
5
+ #include <cstdint>
6
+ #include <cstring>
7
+ #include <iterator>
8
+ #include <limits>
9
+ #include <type_traits>
10
+
11
+ #include "float_common.h"
12
+
13
+ #ifdef FASTFLOAT_SSE2
14
+ #include <emmintrin.h>
15
+ #endif
16
+
17
+ #ifdef FASTFLOAT_NEON
18
+ #include <arm_neon.h>
19
+ #endif
20
+
21
+ namespace fast_float {
22
+
23
+ template <typename UC> fastfloat_really_inline constexpr bool has_simd_opt() {
24
+ #ifdef FASTFLOAT_HAS_SIMD
25
+ return std::is_same<UC, char16_t>::value;
26
+ #else
27
+ return false;
28
+ #endif
29
+ }
30
+
31
+ // Next function can be micro-optimized, but compilers are entirely
32
+ // able to optimize it well.
33
+ template <typename UC>
34
+ fastfloat_really_inline constexpr bool is_integer(UC c) noexcept {
35
+ return (unsigned)(c - UC('0')) <= 9u;
36
+ }
37
+
38
+ fastfloat_really_inline constexpr uint64_t byteswap(uint64_t val) {
39
+ return (val & 0xFF00000000000000) >> 56 | (val & 0x00FF000000000000) >> 40 |
40
+ (val & 0x0000FF0000000000) >> 24 | (val & 0x000000FF00000000) >> 8 |
41
+ (val & 0x00000000FF000000) << 8 | (val & 0x0000000000FF0000) << 24 |
42
+ (val & 0x000000000000FF00) << 40 | (val & 0x00000000000000FF) << 56;
43
+ }
44
+
45
+ fastfloat_really_inline constexpr uint32_t byteswap_32(uint32_t val) {
46
+ return (val >> 24) | ((val >> 8) & 0x0000FF00u) | ((val << 8) & 0x00FF0000u) |
47
+ (val << 24);
48
+ }
49
+
50
+ // Read 8 UC into a u64. Truncates UC if not char.
51
+ template <typename UC>
52
+ fastfloat_really_inline FASTFLOAT_CONSTEXPR20 uint64_t
53
+ read8_to_u64(UC const *chars) {
54
+ if (cpp20_and_in_constexpr() || !std::is_same<UC, char>::value) {
55
+ uint64_t val = 0;
56
+ for (int i = 0; i < 8; ++i) {
57
+ val |= uint64_t(uint8_t(*chars)) << (i * 8);
58
+ ++chars;
59
+ }
60
+ return val;
61
+ }
62
+ uint64_t val;
63
+ ::memcpy(&val, chars, sizeof(uint64_t));
64
+ #if FASTFLOAT_IS_BIG_ENDIAN == 1
65
+ // Need to read as-if the number was in little-endian order.
66
+ val = byteswap(val);
67
+ #endif
68
+ return val;
69
+ }
70
+
71
+ // Read 4 UC into a u32. Truncates UC if not char.
72
+ template <typename UC>
73
+ fastfloat_really_inline FASTFLOAT_CONSTEXPR20 uint32_t
74
+ read4_to_u32(UC const *chars) {
75
+ if (cpp20_and_in_constexpr() || !std::is_same<UC, char>::value) {
76
+ uint32_t val = 0;
77
+ for (int i = 0; i < 4; ++i) {
78
+ val |= uint32_t(uint8_t(*chars)) << (i * 8);
79
+ ++chars;
80
+ }
81
+ return val;
82
+ }
83
+ uint32_t val;
84
+ ::memcpy(&val, chars, sizeof(uint32_t));
85
+ #if FASTFLOAT_IS_BIG_ENDIAN == 1
86
+ val = byteswap_32(val);
87
+ #endif
88
+ return val;
89
+ }
90
+ #ifdef FASTFLOAT_SSE2
91
+
92
+ fastfloat_really_inline uint64_t simd_read8_to_u64(__m128i const data) {
93
+ FASTFLOAT_SIMD_DISABLE_WARNINGS
94
+ __m128i const packed = _mm_packus_epi16(data, data);
95
+ #ifdef FASTFLOAT_64BIT
96
+ return uint64_t(_mm_cvtsi128_si64(packed));
97
+ #else
98
+ uint64_t value;
99
+ // Visual Studio + older versions of GCC don't support _mm_storeu_si64
100
+ _mm_storel_epi64(reinterpret_cast<__m128i *>(&value), packed);
101
+ return value;
102
+ #endif
103
+ FASTFLOAT_SIMD_RESTORE_WARNINGS
104
+ }
105
+
106
+ fastfloat_really_inline uint64_t simd_read8_to_u64(char16_t const *chars) {
107
+ FASTFLOAT_SIMD_DISABLE_WARNINGS
108
+ return simd_read8_to_u64(
109
+ _mm_loadu_si128(reinterpret_cast<__m128i const *>(chars)));
110
+ FASTFLOAT_SIMD_RESTORE_WARNINGS
111
+ }
112
+
113
+ #elif defined(FASTFLOAT_NEON)
114
+
115
+ fastfloat_really_inline uint64_t simd_read8_to_u64(uint16x8_t const data) {
116
+ FASTFLOAT_SIMD_DISABLE_WARNINGS
117
+ uint8x8_t utf8_packed = vmovn_u16(data);
118
+ return vget_lane_u64(vreinterpret_u64_u8(utf8_packed), 0);
119
+ FASTFLOAT_SIMD_RESTORE_WARNINGS
120
+ }
121
+
122
+ fastfloat_really_inline uint64_t simd_read8_to_u64(char16_t const *chars) {
123
+ FASTFLOAT_SIMD_DISABLE_WARNINGS
124
+ return simd_read8_to_u64(
125
+ vld1q_u16(reinterpret_cast<uint16_t const *>(chars)));
126
+ FASTFLOAT_SIMD_RESTORE_WARNINGS
127
+ }
128
+
129
+ #endif // FASTFLOAT_SSE2
130
+
131
+ // MSVC SFINAE is broken pre-VS2017
132
+ #if defined(_MSC_VER) && _MSC_VER <= 1900
133
+ template <typename UC>
134
+ #else
135
+ template <typename UC, FASTFLOAT_ENABLE_IF(!has_simd_opt<UC>()) = 0>
136
+ #endif
137
+ // dummy for compile
138
+ uint64_t simd_read8_to_u64(UC const *) {
139
+ return 0;
140
+ }
141
+
142
+ // credit @aqrit
143
+ fastfloat_really_inline FASTFLOAT_CONSTEXPR14 uint32_t
144
+ parse_eight_digits_unrolled(uint64_t val) {
145
+ uint64_t const mask = 0x000000FF000000FF;
146
+ uint64_t const mul1 = 0x000F424000000064; // 100 + (1000000ULL << 32)
147
+ uint64_t const mul2 = 0x0000271000000001; // 1 + (10000ULL << 32)
148
+ val -= 0x3030303030303030;
149
+ val = (val * 10) + (val >> 8); // val = (val * 2561) >> 8;
150
+ val = (((val & mask) * mul1) + (((val >> 16) & mask) * mul2)) >> 32;
151
+ return uint32_t(val);
152
+ }
153
+
154
+ // Call this if chars are definitely 8 digits.
155
+ template <typename UC>
156
+ fastfloat_really_inline FASTFLOAT_CONSTEXPR20 uint32_t
157
+ parse_eight_digits_unrolled(UC const *chars) noexcept {
158
+ if (cpp20_and_in_constexpr() || !has_simd_opt<UC>()) {
159
+ return parse_eight_digits_unrolled(read8_to_u64(chars)); // truncation okay
160
+ }
161
+ return parse_eight_digits_unrolled(simd_read8_to_u64(chars));
162
+ }
163
+
164
+ // credit @aqrit
165
+ fastfloat_really_inline constexpr bool
166
+ is_made_of_eight_digits_fast(uint64_t val) noexcept {
167
+ return !((((val + 0x4646464646464646) | (val - 0x3030303030303030)) &
168
+ 0x8080808080808080));
169
+ }
170
+
171
+ fastfloat_really_inline constexpr bool
172
+ is_made_of_four_digits_fast(uint32_t val) noexcept {
173
+ return !((((val + 0x46464646) | (val - 0x30303030)) & 0x80808080));
174
+ }
175
+
176
+ fastfloat_really_inline FASTFLOAT_CONSTEXPR14 uint32_t
177
+ parse_four_digits_unrolled(uint32_t val) noexcept {
178
+ val -= 0x30303030;
179
+ val = (val * 10) + (val >> 8);
180
+ return (((val & 0x00FF00FF) * 0x00640001) >> 16) & 0xFFFF;
181
+ }
182
+
183
+ #ifdef FASTFLOAT_HAS_SIMD
184
+
185
+ // Call this if chars might not be 8 digits.
186
+ // Using this style (instead of is_made_of_eight_digits_fast() then
187
+ // parse_eight_digits_unrolled()) ensures we don't load SIMD registers twice.
188
+ fastfloat_really_inline FASTFLOAT_CONSTEXPR20 bool
189
+ simd_parse_if_eight_digits_unrolled(char16_t const *chars,
190
+ uint64_t &i) noexcept {
191
+ if (cpp20_and_in_constexpr()) {
192
+ return false;
193
+ }
194
+ #ifdef FASTFLOAT_SSE2
195
+ FASTFLOAT_SIMD_DISABLE_WARNINGS
196
+ __m128i const data =
197
+ _mm_loadu_si128(reinterpret_cast<__m128i const *>(chars));
198
+
199
+ // (x - '0') <= 9
200
+ // http://0x80.pl/articles/simd-parsing-int-sequences.html
201
+ __m128i const t0 = _mm_add_epi16(data, _mm_set1_epi16(32720));
202
+ __m128i const t1 = _mm_cmpgt_epi16(t0, _mm_set1_epi16(-32759));
203
+
204
+ if (_mm_movemask_epi8(t1) == 0) {
205
+ i = i * 100000000 + parse_eight_digits_unrolled(simd_read8_to_u64(data));
206
+ return true;
207
+ } else
208
+ return false;
209
+ FASTFLOAT_SIMD_RESTORE_WARNINGS
210
+ #elif defined(FASTFLOAT_NEON)
211
+ FASTFLOAT_SIMD_DISABLE_WARNINGS
212
+ uint16x8_t const data = vld1q_u16(reinterpret_cast<uint16_t const *>(chars));
213
+
214
+ // (x - '0') <= 9
215
+ // http://0x80.pl/articles/simd-parsing-int-sequences.html
216
+ uint16x8_t const t0 = vsubq_u16(data, vmovq_n_u16('0'));
217
+ uint16x8_t const mask = vcltq_u16(t0, vmovq_n_u16('9' - '0' + 1));
218
+
219
+ if (vminvq_u16(mask) == 0xFFFF) {
220
+ i = i * 100000000 + parse_eight_digits_unrolled(simd_read8_to_u64(data));
221
+ return true;
222
+ } else
223
+ return false;
224
+ FASTFLOAT_SIMD_RESTORE_WARNINGS
225
+ #else
226
+ (void)chars;
227
+ (void)i;
228
+ return false;
229
+ #endif // FASTFLOAT_SSE2
230
+ }
231
+
232
+ #endif // FASTFLOAT_HAS_SIMD
233
+
234
+ // MSVC SFINAE is broken pre-VS2017
235
+ #if defined(_MSC_VER) && _MSC_VER <= 1900
236
+ template <typename UC>
237
+ #else
238
+ template <typename UC, FASTFLOAT_ENABLE_IF(!has_simd_opt<UC>()) = 0>
239
+ #endif
240
+ // dummy for compile
241
+ bool simd_parse_if_eight_digits_unrolled(UC const *, uint64_t &) {
242
+ return 0;
243
+ }
244
+
245
+ template <typename UC, FASTFLOAT_ENABLE_IF(!std::is_same<UC, char>::value) = 0>
246
+ fastfloat_really_inline FASTFLOAT_CONSTEXPR20 void
247
+ loop_parse_if_eight_digits(UC const *&p, UC const *const pend, uint64_t &i) {
248
+ if (!has_simd_opt<UC>()) {
249
+ return;
250
+ }
251
+ while ((std::distance(p, pend) >= 8) &&
252
+ simd_parse_if_eight_digits_unrolled(
253
+ p, i)) { // in rare cases, this will overflow, but that's ok
254
+ p += 8;
255
+ }
256
+ }
257
+
258
+ fastfloat_really_inline FASTFLOAT_CONSTEXPR20 void
259
+ loop_parse_if_eight_digits(char const *&p, char const *const pend,
260
+ uint64_t &i) {
261
+ // optimizes better than parse_if_eight_digits_unrolled() for UC = char.
262
+ while ((std::distance(p, pend) >= 8) &&
263
+ is_made_of_eight_digits_fast(read8_to_u64(p))) {
264
+ i = i * 100000000 +
265
+ parse_eight_digits_unrolled(read8_to_u64(
266
+ p)); // in rare cases, this will overflow, but that's ok
267
+ p += 8;
268
+ }
269
+ }
270
+
271
+ enum class parse_error {
272
+ no_error,
273
+ // [JSON-only] The minus sign must be followed by an integer.
274
+ missing_integer_after_sign,
275
+ // A sign must be followed by an integer or dot.
276
+ missing_integer_or_dot_after_sign,
277
+ // [JSON-only] The integer part must not have leading zeros.
278
+ leading_zeros_in_integer_part,
279
+ // [JSON-only] The integer part must have at least one digit.
280
+ no_digits_in_integer_part,
281
+ // [JSON-only] If there is a decimal point, there must be digits in the
282
+ // fractional part.
283
+ no_digits_in_fractional_part,
284
+ // The mantissa must have at least one digit.
285
+ no_digits_in_mantissa,
286
+ // Scientific notation requires an exponential part.
287
+ missing_exponential_part,
288
+ };
289
+
290
+ template <typename UC> struct parsed_number_string_t {
291
+ int64_t exponent{0};
292
+ uint64_t mantissa{0};
293
+ UC const *lastmatch{nullptr};
294
+ bool negative{false};
295
+ bool valid{false};
296
+ bool too_many_digits{false};
297
+ // contains the range of the significant digits
298
+ span<UC const> integer{}; // non-nullable
299
+ span<UC const> fraction{}; // nullable
300
+ parse_error error{parse_error::no_error};
301
+ };
302
+
303
+ using byte_span = span<char const>;
304
+ using parsed_number_string = parsed_number_string_t<char>;
305
+
306
+ template <typename UC>
307
+ fastfloat_really_inline FASTFLOAT_CONSTEXPR20 parsed_number_string_t<UC>
308
+ report_parse_error(UC const *p, parse_error error) {
309
+ parsed_number_string_t<UC> answer;
310
+ answer.valid = false;
311
+ answer.lastmatch = p;
312
+ answer.error = error;
313
+ return answer;
314
+ }
315
+
316
+ // Assuming that you use no more than 19 digits, this will
317
+ // parse an ASCII string.
318
+ template <bool basic_json_fmt, typename UC>
319
+ fastfloat_really_inline FASTFLOAT_CONSTEXPR20 parsed_number_string_t<UC>
320
+ parse_number_string(UC const *p, UC const *pend,
321
+ parse_options_t<UC> options) noexcept {
322
+ chars_format const fmt = detail::adjust_for_feature_macros(options.format);
323
+ UC const decimal_point = options.decimal_point;
324
+
325
+ parsed_number_string_t<UC> answer;
326
+ answer.valid = false;
327
+ answer.too_many_digits = false;
328
+ // assume p < pend, so dereference without checks;
329
+ answer.negative = (*p == UC('-'));
330
+ // C++17 20.19.3.(7.1) explicitly forbids '+' sign here
331
+ if ((*p == UC('-')) || (uint64_t(fmt & chars_format::allow_leading_plus) &&
332
+ !basic_json_fmt && *p == UC('+'))) {
333
+ ++p;
334
+ if (p == pend) {
335
+ return report_parse_error<UC>(
336
+ p, parse_error::missing_integer_or_dot_after_sign);
337
+ }
338
+ FASTFLOAT_IF_CONSTEXPR17(basic_json_fmt) {
339
+ if (!is_integer(*p)) { // a sign must be followed by an integer
340
+ return report_parse_error<UC>(p,
341
+ parse_error::missing_integer_after_sign);
342
+ }
343
+ }
344
+ else {
345
+ if (!is_integer(*p) &&
346
+ (*p !=
347
+ decimal_point)) { // a sign must be followed by an integer or the dot
348
+ return report_parse_error<UC>(
349
+ p, parse_error::missing_integer_or_dot_after_sign);
350
+ }
351
+ }
352
+ }
353
+ UC const *const start_digits = p;
354
+
355
+ uint64_t i = 0; // an unsigned int avoids signed overflows (which are bad)
356
+
357
+ while ((p != pend) && is_integer(*p)) {
358
+ // a multiplication by 10 is cheaper than an arbitrary integer
359
+ // multiplication
360
+ i = 10 * i +
361
+ uint64_t(*p -
362
+ UC('0')); // might overflow, we will handle the overflow later
363
+ ++p;
364
+ }
365
+ UC const *const end_of_integer_part = p;
366
+ int64_t digit_count = int64_t(end_of_integer_part - start_digits);
367
+ answer.integer = span<UC const>(start_digits, size_t(digit_count));
368
+ FASTFLOAT_IF_CONSTEXPR17(basic_json_fmt) {
369
+ // at least 1 digit in integer part, without leading zeros
370
+ if (digit_count == 0) {
371
+ return report_parse_error<UC>(p, parse_error::no_digits_in_integer_part);
372
+ }
373
+ if ((start_digits[0] == UC('0') && digit_count > 1)) {
374
+ return report_parse_error<UC>(start_digits,
375
+ parse_error::leading_zeros_in_integer_part);
376
+ }
377
+ }
378
+
379
+ int64_t exponent = 0;
380
+ bool const has_decimal_point = (p != pend) && (*p == decimal_point);
381
+ if (has_decimal_point) {
382
+ ++p;
383
+ UC const *before = p;
384
+ // can occur at most twice without overflowing, but let it occur more, since
385
+ // for integers with many digits, digit parsing is the primary bottleneck.
386
+ loop_parse_if_eight_digits(p, pend, i);
387
+
388
+ while ((p != pend) && is_integer(*p)) {
389
+ uint8_t digit = uint8_t(*p - UC('0'));
390
+ ++p;
391
+ i = i * 10 + digit; // in rare cases, this will overflow, but that's ok
392
+ }
393
+ exponent = before - p;
394
+ answer.fraction = span<UC const>(before, size_t(p - before));
395
+ digit_count -= exponent;
396
+ }
397
+ FASTFLOAT_IF_CONSTEXPR17(basic_json_fmt) {
398
+ // at least 1 digit in fractional part
399
+ if (has_decimal_point && exponent == 0) {
400
+ return report_parse_error<UC>(p,
401
+ parse_error::no_digits_in_fractional_part);
402
+ }
403
+ }
404
+ else if (digit_count == 0) { // we must have encountered at least one integer!
405
+ return report_parse_error<UC>(p, parse_error::no_digits_in_mantissa);
406
+ }
407
+ int64_t exp_number = 0; // explicit exponential part
408
+ if ((uint64_t(fmt & chars_format::scientific) && (p != pend) &&
409
+ ((UC('e') == *p) || (UC('E') == *p))) ||
410
+ (uint64_t(fmt & detail::basic_fortran_fmt) && (p != pend) &&
411
+ ((UC('+') == *p) || (UC('-') == *p) || (UC('d') == *p) ||
412
+ (UC('D') == *p)))) {
413
+ UC const *location_of_e = p;
414
+ if ((UC('e') == *p) || (UC('E') == *p) || (UC('d') == *p) ||
415
+ (UC('D') == *p)) {
416
+ ++p;
417
+ }
418
+ bool neg_exp = false;
419
+ if ((p != pend) && (UC('-') == *p)) {
420
+ neg_exp = true;
421
+ ++p;
422
+ } else if ((p != pend) &&
423
+ (UC('+') ==
424
+ *p)) { // '+' on exponent is allowed by C++17 20.19.3.(7.1)
425
+ ++p;
426
+ }
427
+ if ((p == pend) || !is_integer(*p)) {
428
+ if (!uint64_t(fmt & chars_format::fixed)) {
429
+ // The exponential part is invalid for scientific notation, so it must
430
+ // be a trailing token for fixed notation. However, fixed notation is
431
+ // disabled, so report a scientific notation error.
432
+ return report_parse_error<UC>(p, parse_error::missing_exponential_part);
433
+ }
434
+ // Otherwise, we will be ignoring the 'e'.
435
+ p = location_of_e;
436
+ } else {
437
+ while ((p != pend) && is_integer(*p)) {
438
+ uint8_t digit = uint8_t(*p - UC('0'));
439
+ if (exp_number < 0x10000000) {
440
+ exp_number = 10 * exp_number + digit;
441
+ }
442
+ ++p;
443
+ }
444
+ if (neg_exp) {
445
+ exp_number = -exp_number;
446
+ }
447
+ exponent += exp_number;
448
+ }
449
+ } else {
450
+ // If it scientific and not fixed, we have to bail out.
451
+ if (uint64_t(fmt & chars_format::scientific) &&
452
+ !uint64_t(fmt & chars_format::fixed)) {
453
+ return report_parse_error<UC>(p, parse_error::missing_exponential_part);
454
+ }
455
+ }
456
+ answer.lastmatch = p;
457
+ answer.valid = true;
458
+
459
+ // If we frequently had to deal with long strings of digits,
460
+ // we could extend our code by using a 128-bit integer instead
461
+ // of a 64-bit integer. However, this is uncommon.
462
+ //
463
+ // We can deal with up to 19 digits.
464
+ if (digit_count > 19) { // this is uncommon
465
+ // It is possible that the integer had an overflow.
466
+ // We have to handle the case where we have 0.0000somenumber.
467
+ // We need to be mindful of the case where we only have zeroes...
468
+ // E.g., 0.000000000...000.
469
+ UC const *start = start_digits;
470
+ while ((start != pend) && (*start == UC('0') || *start == decimal_point)) {
471
+ if (*start == UC('0')) {
472
+ digit_count--;
473
+ }
474
+ start++;
475
+ }
476
+
477
+ if (digit_count > 19) {
478
+ answer.too_many_digits = true;
479
+ // Let us start again, this time, avoiding overflows.
480
+ // We don't need to call if is_integer, since we use the
481
+ // pre-tokenized spans from above.
482
+ i = 0;
483
+ p = answer.integer.ptr;
484
+ UC const *int_end = p + answer.integer.len();
485
+ uint64_t const minimal_nineteen_digit_integer{1000000000000000000};
486
+ while ((i < minimal_nineteen_digit_integer) && (p != int_end)) {
487
+ i = i * 10 + uint64_t(*p - UC('0'));
488
+ ++p;
489
+ }
490
+ if (i >= minimal_nineteen_digit_integer) { // We have a big integer
491
+ exponent = end_of_integer_part - p + exp_number;
492
+ } else { // We have a value with a fractional component.
493
+ p = answer.fraction.ptr;
494
+ UC const *frac_end = p + answer.fraction.len();
495
+ while ((i < minimal_nineteen_digit_integer) && (p != frac_end)) {
496
+ i = i * 10 + uint64_t(*p - UC('0'));
497
+ ++p;
498
+ }
499
+ exponent = answer.fraction.ptr - p + exp_number;
500
+ }
501
+ // We have now corrected both exponent and i, to a truncated value
502
+ }
503
+ }
504
+ answer.exponent = exponent;
505
+ answer.mantissa = i;
506
+ return answer;
507
+ }
508
+
509
+ template <typename T, typename UC>
510
+ fastfloat_really_inline FASTFLOAT_CONSTEXPR20 from_chars_result_t<UC>
511
+ parse_int_string(UC const *p, UC const *pend, T &value,
512
+ parse_options_t<UC> options) {
513
+ chars_format const fmt = detail::adjust_for_feature_macros(options.format);
514
+ int const base = options.base;
515
+
516
+ from_chars_result_t<UC> answer;
517
+
518
+ UC const *const first = p;
519
+
520
+ bool const negative = (*p == UC('-'));
521
+ #ifdef FASTFLOAT_VISUAL_STUDIO
522
+ #pragma warning(push)
523
+ #pragma warning(disable : 4127)
524
+ #endif
525
+ if (!std::is_signed<T>::value && negative) {
526
+ #ifdef FASTFLOAT_VISUAL_STUDIO
527
+ #pragma warning(pop)
528
+ #endif
529
+ answer.ec = std::errc::invalid_argument;
530
+ answer.ptr = first;
531
+ return answer;
532
+ }
533
+ if ((*p == UC('-')) ||
534
+ (uint64_t(fmt & chars_format::allow_leading_plus) && (*p == UC('+')))) {
535
+ ++p;
536
+ }
537
+
538
+ UC const *const start_num = p;
539
+
540
+ while (p != pend && *p == UC('0')) {
541
+ ++p;
542
+ }
543
+
544
+ bool const has_leading_zeros = p > start_num;
545
+
546
+ UC const *const start_digits = p;
547
+
548
+ FASTFLOAT_IF_CONSTEXPR17((std::is_same<T, std::uint8_t>::value)) {
549
+ if (base == 10) {
550
+ const size_t len = (size_t)(pend - p);
551
+ if (len == 0) {
552
+ if (has_leading_zeros) {
553
+ value = 0;
554
+ answer.ec = std::errc();
555
+ answer.ptr = p;
556
+ } else {
557
+ answer.ec = std::errc::invalid_argument;
558
+ answer.ptr = first;
559
+ }
560
+ return answer;
561
+ }
562
+
563
+ uint32_t digits;
564
+
565
+ #if FASTFLOAT_HAS_IS_CONSTANT_EVALUATED && FASTFLOAT_HAS_BIT_CAST
566
+ if (std::is_constant_evaluated()) {
567
+ uint8_t str[4]{};
568
+ for (size_t j = 0; j < 4 && j < len; ++j) {
569
+ str[j] = static_cast<uint8_t>(p[j]);
570
+ }
571
+ digits = std::bit_cast<uint32_t>(str);
572
+ #if FASTFLOAT_IS_BIG_ENDIAN
573
+ digits = byteswap_32(digits);
574
+ #endif
575
+ }
576
+ #else
577
+ if (false) {
578
+ }
579
+ #endif
580
+ else if (len >= 4) {
581
+ ::memcpy(&digits, p, 4);
582
+ #if FASTFLOAT_IS_BIG_ENDIAN
583
+ digits = byteswap_32(digits);
584
+ #endif
585
+ } else {
586
+ uint32_t b0 = static_cast<uint8_t>(p[0]);
587
+ uint32_t b1 = (len > 1) ? static_cast<uint8_t>(p[1]) : 0xFFu;
588
+ uint32_t b2 = (len > 2) ? static_cast<uint8_t>(p[2]) : 0xFFu;
589
+ uint32_t b3 = 0xFFu;
590
+ digits = b0 | (b1 << 8) | (b2 << 16) | (b3 << 24);
591
+ }
592
+
593
+ uint32_t magic =
594
+ ((digits + 0x46464646u) | (digits - 0x30303030u)) & 0x80808080u;
595
+ uint32_t tz = (uint32_t)countr_zero_32(magic); // 7, 15, 23, 31, or 32
596
+ uint32_t nd = (tz == 32) ? 4 : (tz >> 3);
597
+ nd = (uint32_t)std::min((size_t)nd, len);
598
+ if (nd == 0) {
599
+ if (has_leading_zeros) {
600
+ value = 0;
601
+ answer.ec = std::errc();
602
+ answer.ptr = p;
603
+ return answer;
604
+ }
605
+ answer.ec = std::errc::invalid_argument;
606
+ answer.ptr = first;
607
+ return answer;
608
+ }
609
+ if (nd > 3) {
610
+ const UC *q = p + nd;
611
+ size_t rem = len - nd;
612
+ while (rem) {
613
+ if (*q < UC('0') || *q > UC('9'))
614
+ break;
615
+ ++q;
616
+ --rem;
617
+ }
618
+ answer.ec = std::errc::result_out_of_range;
619
+ answer.ptr = q;
620
+ return answer;
621
+ }
622
+
623
+ digits ^= 0x30303030u;
624
+ digits <<= ((4 - nd) * 8);
625
+
626
+ uint32_t check = ((digits >> 24) & 0xff) | ((digits >> 8) & 0xff00) |
627
+ ((digits << 8) & 0xff0000);
628
+ if (check > 0x00020505) {
629
+ answer.ec = std::errc::result_out_of_range;
630
+ answer.ptr = p + nd;
631
+ return answer;
632
+ }
633
+ value = (uint8_t)((0x640a01 * digits) >> 24);
634
+ answer.ec = std::errc();
635
+ answer.ptr = p + nd;
636
+ return answer;
637
+ }
638
+ }
639
+
640
+ FASTFLOAT_IF_CONSTEXPR17((std::is_same<T, std::uint16_t>::value)) {
641
+ if (base == 10) {
642
+ const size_t len = size_t(pend - p);
643
+ if (len == 0) {
644
+ if (has_leading_zeros) {
645
+ value = 0;
646
+ answer.ec = std::errc();
647
+ answer.ptr = p;
648
+ } else {
649
+ answer.ec = std::errc::invalid_argument;
650
+ answer.ptr = first;
651
+ }
652
+ return answer;
653
+ }
654
+
655
+ if (len >= 4) {
656
+ uint32_t digits = read4_to_u32(p);
657
+ if (is_made_of_four_digits_fast(digits)) {
658
+ uint32_t v = parse_four_digits_unrolled(digits);
659
+ if (len >= 5 && is_integer(p[4])) {
660
+ v = v * 10 + uint32_t(p[4] - '0');
661
+ if (len >= 6 && is_integer(p[5])) {
662
+ answer.ec = std::errc::result_out_of_range;
663
+ const UC *q = p + 5;
664
+ while (q != pend && is_integer(*q)) {
665
+ q++;
666
+ }
667
+ answer.ptr = q;
668
+ return answer;
669
+ }
670
+ if (v > 65535) {
671
+ answer.ec = std::errc::result_out_of_range;
672
+ answer.ptr = p + 5;
673
+ return answer;
674
+ }
675
+ value = uint16_t(v);
676
+ answer.ec = std::errc();
677
+ answer.ptr = p + 5;
678
+ return answer;
679
+ }
680
+ // 4 digits
681
+ value = uint16_t(v);
682
+ answer.ec = std::errc();
683
+ answer.ptr = p + 4;
684
+ return answer;
685
+ }
686
+ }
687
+ }
688
+ }
689
+
690
+ uint64_t i = 0;
691
+ if (base == 10) {
692
+ loop_parse_if_eight_digits(p, pend, i); // use SIMD if possible
693
+ }
694
+ while (p != pend) {
695
+ uint8_t digit = ch_to_digit(*p);
696
+ if (digit >= base) {
697
+ break;
698
+ }
699
+ i = uint64_t(base) * i + digit; // might overflow, check this later
700
+ p++;
701
+ }
702
+
703
+ size_t digit_count = size_t(p - start_digits);
704
+
705
+ if (digit_count == 0) {
706
+ if (has_leading_zeros) {
707
+ value = 0;
708
+ answer.ec = std::errc();
709
+ answer.ptr = p;
710
+ } else {
711
+ answer.ec = std::errc::invalid_argument;
712
+ answer.ptr = first;
713
+ }
714
+ return answer;
715
+ }
716
+
717
+ answer.ptr = p;
718
+
719
+ // check u64 overflow
720
+ size_t max_digits = max_digits_u64(base);
721
+ if (digit_count > max_digits) {
722
+ answer.ec = std::errc::result_out_of_range;
723
+ return answer;
724
+ }
725
+ // this check can be eliminated for all other types, but they will all require
726
+ // a max_digits(base) equivalent
727
+ if (digit_count == max_digits && i < min_safe_u64(base)) {
728
+ answer.ec = std::errc::result_out_of_range;
729
+ return answer;
730
+ }
731
+
732
+ // check other types overflow
733
+ if (!std::is_same<T, uint64_t>::value) {
734
+ if (i > uint64_t(std::numeric_limits<T>::max()) + uint64_t(negative)) {
735
+ answer.ec = std::errc::result_out_of_range;
736
+ return answer;
737
+ }
738
+ }
739
+
740
+ if (negative) {
741
+ #ifdef FASTFLOAT_VISUAL_STUDIO
742
+ #pragma warning(push)
743
+ #pragma warning(disable : 4146)
744
+ #endif
745
+ // this weird workaround is required because:
746
+ // - converting unsigned to signed when its value is greater than signed max
747
+ // is UB pre-C++23.
748
+ // - reinterpret_casting (~i + 1) would work, but it is not constexpr
749
+ // this is always optimized into a neg instruction (note: T is an integer
750
+ // type)
751
+ value = T(-std::numeric_limits<T>::max() -
752
+ T(i - uint64_t(std::numeric_limits<T>::max())));
753
+ #ifdef FASTFLOAT_VISUAL_STUDIO
754
+ #pragma warning(pop)
755
+ #endif
756
+ } else {
757
+ value = T(i);
758
+ }
759
+
760
+ answer.ec = std::errc();
761
+ return answer;
762
+ }
763
+
764
+ } // namespace fast_float
765
+
766
+ #endif