1 #ifndef SIMDJSON_GENERIC_ATOMPARSING_H
3 #ifndef SIMDJSON_CONDITIONAL_INCLUDE
4 #define SIMDJSON_GENERIC_ATOMPARSING_H
5 #include "simdjson/generic/base.h"
6 #include "simdjson/generic/jsoncharutils.h"
12 namespace SIMDJSON_IMPLEMENTATION {
15 namespace atomparsing {
23 simdjson_inline uint32_t string_to_uint32(
const char* str) { uint32_t val; std::memcpy(&val, str,
sizeof(uint32_t));
return val; }
29 simdjson_inline uint32_t str4ncmp(
const uint8_t *src,
const char* atom) {
31 static_assert(
sizeof(uint32_t) <=
SIMDJSON_PADDING,
"SIMDJSON_PADDING must be larger than 4 bytes");
32 std::memcpy(&srcval, src,
sizeof(uint32_t));
33 return srcval ^ string_to_uint32(atom);
37 simdjson_inline
bool is_valid_true_atom(
const uint8_t *src) {
38 return (str4ncmp(src,
"true") | jsoncharutils::is_not_structural_or_whitespace(src[4])) == 0;
42 simdjson_inline
bool is_valid_true_atom(
const uint8_t *src,
size_t len) {
43 if (len > 4) {
return is_valid_true_atom(src); }
44 else if (len == 4) {
return !str4ncmp(src,
"true"); }
45 else {
return false; }
49 simdjson_inline
bool is_valid_false_atom(
const uint8_t *src) {
50 return (str4ncmp(src+1,
"alse") | jsoncharutils::is_not_structural_or_whitespace(src[5])) == 0;
54 simdjson_inline
bool is_valid_false_atom(
const uint8_t *src,
size_t len) {
55 if (len > 5) {
return is_valid_false_atom(src); }
56 else if (len == 5) {
return !str4ncmp(src+1,
"alse"); }
57 else {
return false; }
61 simdjson_inline
bool is_valid_null_atom(
const uint8_t *src) {
62 return (str4ncmp(src,
"null") | jsoncharutils::is_not_structural_or_whitespace(src[4])) == 0;
66 simdjson_inline
bool is_valid_null_atom(
const uint8_t *src,
size_t len) {
67 if (len > 4) {
return is_valid_null_atom(src); }
68 else if (len == 4) {
return !str4ncmp(src,
"null"); }
69 else {
return false; }
The top level simdjson namespace, containing everything the library provides.
constexpr size_t SIMDJSON_PADDING
The amount of padding needed in a buffer to parse JSON.