mirror of
https://github.com/simdjson/simdjson
synced 2026-06-08 17:27:07 +00:00
69 lines
2.1 KiB
C++
69 lines
2.1 KiB
C++
#ifndef SIMDJSON_FALLBACK_STRINGPARSING_DEFS_H
|
|
#define SIMDJSON_FALLBACK_STRINGPARSING_DEFS_H
|
|
|
|
#ifndef SIMDJSON_CONDITIONAL_INCLUDE
|
|
#include "simdjson/fallback/base.h"
|
|
#endif // SIMDJSON_CONDITIONAL_INCLUDE
|
|
|
|
namespace simdjson {
|
|
namespace fallback {
|
|
namespace {
|
|
|
|
// Holds backslashes and quotes locations.
|
|
struct backslash_and_quote {
|
|
public:
|
|
static constexpr uint32_t BYTES_PROCESSED = 1;
|
|
simdjson_inline static backslash_and_quote copy_and_find(const uint8_t *src, uint8_t *dst);
|
|
/////////////
|
|
/// TODO: This function is not used in the codebase. It is not clear if it is needed.
|
|
/////////////
|
|
simdjson_inline static bool requires_escaping(const uint8_t *src, size_t len);
|
|
|
|
simdjson_inline bool has_quote_first() { return c == '"'; }
|
|
simdjson_inline bool has_backslash() { return c == '\\'; }
|
|
simdjson_inline int quote_index() { return c == '"' ? 0 : 1; }
|
|
simdjson_inline int backslash_index() { return c == '\\' ? 0 : 1; }
|
|
|
|
uint8_t c;
|
|
}; // struct backslash_and_quote
|
|
|
|
|
|
simdjson_inline bool backslash_and_quote::requires_escaping(const uint8_t *src, size_t len) {
|
|
bool requires_escaping = false;
|
|
for(size_t i = 0; i < len; i++) {
|
|
uint8_t c = src[i];
|
|
requires_escaping |= (c == '\\' || c == '"' || c < 32);
|
|
}
|
|
return requires_escaping;
|
|
}
|
|
|
|
simdjson_inline backslash_and_quote backslash_and_quote::copy_and_find(const uint8_t *src, uint8_t *dst) {
|
|
// store to dest unconditionally - we can overwrite the bits we don't like later
|
|
dst[0] = src[0];
|
|
return { src[0] };
|
|
}
|
|
|
|
|
|
struct escaping {
|
|
static constexpr uint32_t BYTES_PROCESSED = 1;
|
|
simdjson_inline static escaping copy_and_find(const uint8_t *src, uint8_t *dst);
|
|
|
|
simdjson_inline bool has_escape() { return escape_bits; }
|
|
simdjson_inline int escape_index() { return 0; }
|
|
|
|
bool escape_bits;
|
|
}; // struct escaping
|
|
|
|
|
|
|
|
simdjson_inline escaping escaping::copy_and_find(const uint8_t *src, uint8_t *dst) {
|
|
dst[0] = src[0];
|
|
return { (src[0] == '\\') || (src[0] == '"') || (src[0] < 32) };
|
|
}
|
|
|
|
} // unnamed namespace
|
|
} // namespace fallback
|
|
} // namespace simdjson
|
|
|
|
#endif // SIMDJSON_FALLBACK_STRINGPARSING_DEFS_H
|