MCPcopy Create free account
hub / github.com/bytedance/sonic-cpp / parseNumber

Method parseNumber

include/sonic/dom/parser.h:220–481  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

218
219 template <typename SAX>
220 sonic_force_inline bool parseNumber(SAX &sax) {
221#define FLOATING_LONGEST_DIGITS 17
222
223#define RETURN_SET_ERROR_CODE(error_code) \
224 do { \
225 pos_ = i; \
226 err_ = error_code; \
227 return true; \
228 } while (0)
229
230#define CHECK_DIGIT() \
231 do { \
232 if (sonic_unlikely(s[i] < '0' || s[i] > '9')) { \
233 RETURN_SET_ERROR_CODE(kParseErrorInvalidChar); \
234 } \
235 } while (0)
236
237#define SET_INT_AND_RETURN(int_val) \
238 do { \
239 if (!sax.Int(int_val)) RETURN_SET_ERROR_CODE(kParseErrorInvalidChar); \
240 RETURN_SET_ERROR_CODE(kErrorNone); \
241 } while (0)
242
243#define SET_UINT_AND_RETURN(int_val) \
244 do { \
245 if (!sax.Uint(int_val)) RETURN_SET_ERROR_CODE(kParseErrorInvalidChar); \
246 RETURN_SET_ERROR_CODE(kErrorNone); \
247 } while (0)
248
249#define SET_DOUBLE_AND_RETURN(dbl) \
250 do { \
251 if (!sax.Double(dbl)) RETURN_SET_ERROR_CODE(kParseErrorInvalidChar); \
252 RETURN_SET_ERROR_CODE(kErrorNone); \
253 } while (0)
254
255#define SET_U64_AS_DOUBLE_AND_RETURN(int_val) \
256 do { \
257 union { \
258 double d; \
259 uint64_t u; \
260 } du; \
261 du.u = int_val; \
262 if (!sax.Double(du.d)) RETURN_SET_ERROR_CODE(kParseErrorInvalidChar); \
263 RETURN_SET_ERROR_CODE(kErrorNone); \
264 } while (0)
265
266 static constexpr uint64_t kUint64Max = 0xFFFFFFFFFFFFFFFF;
267 int sgn = -1;
268 int man_nd = 0; // # digits of mantissa, 10 ^ 19 fits uint64_t
269 int exp10 = 0; // 10-based exponet of float point number
270 int trunc = 0;
271 uint64_t man = 0; // mantissa of float point number
272 size_t i = pos_ - 1;
273 size_t exp10_s = i;
274 const char *s = reinterpret_cast<const char *>(json_buf_);
275 using internal::is_digit;
276
277 /* check sign */

Callers

nothing calls this directly

Calls 4

is_digitFunction · 0.85
ParseFloatingNormalFastFunction · 0.85
simd_str2intFunction · 0.50
DoubleMethod · 0.45

Tested by

no test coverage detected