1 #ifndef SIMDJSON_GENERIC_ONDEMAND_RAW_JSON_STRING_INL_H
3 #ifndef SIMDJSON_CONDITIONAL_INCLUDE
4 #define SIMDJSON_GENERIC_ONDEMAND_RAW_JSON_STRING_INL_H
5 #include "simdjson/generic/ondemand/base.h"
6 #include "simdjson/generic/ondemand/raw_json_string.h"
7 #include "simdjson/generic/ondemand/json_iterator-inl.h"
8 #include "simdjson/generic/implementation_simdjson_result_base-inl.h"
13 namespace SIMDJSON_IMPLEMENTATION {
18 simdjson_inline
const char *
raw_json_string::raw() const noexcept {
return reinterpret_cast<const char *
>(buf); }
24 for(;pos < target.size() && target[pos] !=
'\\';pos++) {}
27 for(;pos < target.size();pos++) {
28 if((target[pos] ==
'"') && !escaping) {
30 }
else if(target[pos] ==
'\\') {
42 for(;target[pos] && target[pos] !=
'\\';pos++) {}
45 for(;target[pos];pos++) {
46 if((target[pos] ==
'"') && !escaping) {
48 }
else if(target[pos] ==
'\\') {
60 return (length >= target.size()) && (raw()[target.size()] ==
'"') && !memcmp(raw(), target.data(), target.size());
67 return (raw()[target.size()] ==
'"') && !memcmp(raw(), target.data(), target.size());
69 const char * r{raw()};
71 for(;pos < target.size();pos++) {
72 if(r[pos] != target[pos]) {
return false; }
74 if(r[pos] !=
'"') {
return false; }
79 const char * r{raw()};
82 for(;pos < target.size();pos++) {
83 if(r[pos] != target[pos]) {
return false; }
87 if((target[pos] ==
'"') && !escaping) {
91 }
else if(target[pos] ==
'\\') {
97 if(r[pos] !=
'"') {
return false; }
105 const char * r{raw()};
107 for(;target[pos];pos++) {
108 if(r[pos] != target[pos]) {
return false; }
110 if(r[pos] !=
'"') {
return false; }
117 const char * r{raw()};
119 bool escaping{
false};
120 for(;target[pos];pos++) {
121 if(r[pos] != target[pos]) {
return false; }
125 if((target[pos] ==
'"') && !escaping) {
129 }
else if(target[pos] ==
'\\') {
130 escaping = !escaping;
135 if(r[pos] !=
'"') {
return false; }
140 return a.unsafe_is_equal(c);
143 simdjson_unused simdjson_inline
bool operator==(std::string_view c,
const raw_json_string &a) noexcept {
147 simdjson_unused simdjson_inline
bool operator!=(
const raw_json_string &a, std::string_view c) noexcept {
151 simdjson_unused simdjson_inline
bool operator!=(std::string_view c,
const raw_json_string &a) noexcept {
156 simdjson_inline simdjson_warn_unused simdjson_result<std::string_view> raw_json_string::unescape(json_iterator &iter,
bool allow_replacement)
const noexcept {
157 return iter.unescape(*
this, allow_replacement);
160 simdjson_inline simdjson_warn_unused simdjson_result<std::string_view> raw_json_string::unescape_wobbly(json_iterator &iter)
const noexcept {
161 return iter.unescape_wobbly(*
this);
164 simdjson_unused simdjson_inline std::ostream &
operator<<(std::ostream &out,
const raw_json_string &str) noexcept {
165 bool in_escape =
false;
166 const char *s = str.raw();
169 case '\\': in_escape = !in_escape;
break;
170 case '"':
if (in_escape) { in_escape =
false; }
else {
return out; }
break;
171 default:
if (in_escape) { in_escape =
false; }
184 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::raw_json_string>::simdjson_result(SIMDJSON_IMPLEMENTATION::ondemand::raw_json_string &&value) noexcept
185 : implementation_simdjson_result_base<SIMDJSON_IMPLEMENTATION::ondemand::raw_json_string>(std::forward<SIMDJSON_IMPLEMENTATION::ondemand::raw_json_string>(value)) {}
186 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::raw_json_string>::simdjson_result(
error_code error) noexcept
187 : implementation_simdjson_result_base<SIMDJSON_IMPLEMENTATION::ondemand::raw_json_string>(error) {}
189 simdjson_inline simdjson_result<const char *> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::raw_json_string>::raw() const noexcept {
193 simdjson_inline simdjson_warn_unused simdjson_result<std::string_view> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::raw_json_string>::unescape(SIMDJSON_IMPLEMENTATION::ondemand::json_iterator &iter,
bool allow_replacement)
const noexcept {
194 if (error()) {
return error(); }
195 return first.unescape(iter, allow_replacement);
197 simdjson_inline simdjson_warn_unused simdjson_result<std::string_view> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::raw_json_string>::unescape_wobbly(SIMDJSON_IMPLEMENTATION::ondemand::json_iterator &iter)
const noexcept {
198 if (error()) {
return error(); }
199 return first.unescape_wobbly(iter);
A string escaped per JSON rules, terminated with quote (").
simdjson_inline bool is_equal(std::string_view target) const noexcept
This compares the current instance to the std::string_view target: returns true if they are byte-by-b...
static simdjson_inline bool is_free_from_unescaped_quote(std::string_view target) noexcept
Returns true if target is free from unescaped quote.
simdjson_inline raw_json_string() noexcept=default
Create a new invalid raw_json_string.
simdjson_inline const char * raw() const noexcept
Get the raw pointer to the beginning of the string in the JSON (just after the ").
simdjson_inline bool unsafe_is_equal(size_t length, std::string_view target) const noexcept
This compares the current instance to the std::string_view target: returns true if they are byte-by-b...
simdjson_unused simdjson_inline bool operator==(const raw_json_string &a, std::string_view c) noexcept
Comparisons between raw_json_string and std::string_view instances are potentially unsafe: the user i...
std::ostream & operator<<(std::ostream &out, json_type type) noexcept
Write the JSON type to the output stream.
The top level simdjson namespace, containing everything the library provides.
error_code
All possible errors returned by simdjson.
constexpr size_t SIMDJSON_PADDING
The amount of padding needed in a buffer to parse JSON.
simdjson_inline error_code error() const noexcept
The error.