souffle  2.0.2-371-g6315b36
Data Structures | Enumerations | Functions | Variables
json11 Namespace Reference

Data Structures

class  Json
 
class  JsonArray
 
class  JsonBoolean
 
class  JsonDouble
 
class  JsonInt
 
class  JsonNull
 
class  JsonObject
 
class  JsonString
 
class  JsonValue
 
struct  NullStruct
 
struct  Statics
 
class  Value
 

Enumerations

enum  JsonParse { STANDARD, COMMENTS }
 

Functions

static void dump (bool value, std::string &out)
 
static void dump (const Json::array &values, std::string &out)
 
static void dump (const Json::object &values, std::string &out)
 
static void dump (const std::string &value, std::string &out)
 
static void dump (double value, std::string &out)
 
static void dump (long long value, std::string &out)
 
static void dump (NullStruct, std::string &out)
 
static std::string esc (char c)
 
static bool in_range (long x, long lower, long upper)
 
std::vector< Jsonparse_multi (const std::string &in, std::string::size_type &parser_stop_pos, std::string &err, JsonParse strategy)
 
static const Jsonstatic_null ()
 
static const Staticsstatics ()
 

Variables

static const int max_depth = 200
 

Enumeration Type Documentation

◆ JsonParse

Enumerator
STANDARD 
COMMENTS 

Definition at line 83 of file json11.h.

83 { STANDARD, COMMENTS };

Function Documentation

◆ dump() [1/7]

static void json11::dump ( bool  value,
std::string &  out 
)
static

Definition at line 305 of file json11.h.

305  {
306  out += value ? "true" : "false";
307 }

◆ dump() [2/7]

static void json11::dump ( const Json::array values,
std::string &  out 
)
static

Definition at line 346 of file json11.h.

346  {
347  bool first = true;
348  out += "[";
349  for (const auto& value : values) {
350  if (!first) out += ", ";
351  value.dump(out);
352  first = false;
353  }
354  out += "]";
355 }

◆ dump() [3/7]

static void json11::dump ( const Json::object values,
std::string &  out 
)
static

Definition at line 357 of file json11.h.

357  {
358  bool first = true;
359  out += "{";
360  for (const auto& kv : values) {
361  if (!first) out += ", ";
362  dump(kv.first, out);
363  out += ": ";
364  kv.second.dump(out);
365  first = false;
366  }
367  out += "}";
368 }

References dump().

Here is the call graph for this function:

◆ dump() [4/7]

static void json11::dump ( const std::string &  value,
std::string &  out 
)
static

Definition at line 309 of file json11.h.

309  {
310  out += '"';
311  for (size_t i = 0; i < value.length(); i++) {
312  const char ch = value[i];
313  if (ch == '\\') {
314  out += "\\\\";
315  } else if (ch == '"') {
316  out += "\\\"";
317  } else if (ch == '\b') {
318  out += "\\b";
319  } else if (ch == '\f') {
320  out += "\\f";
321  } else if (ch == '\n') {
322  out += "\\n";
323  } else if (ch == '\r') {
324  out += "\\r";
325  } else if (ch == '\t') {
326  out += "\\t";
327  } else if (static_cast<uint8_t>(ch) <= 0x1f) {
328  char buf[8];
329  snprintf(buf, sizeof buf, "\\u%04x", ch);
330  out += buf;
331  } else if (static_cast<uint8_t>(ch) == 0xe2 && static_cast<uint8_t>(value[i + 1]) == 0x80 &&
332  static_cast<uint8_t>(value[i + 2]) == 0xa8) {
333  out += "\\u2028";
334  i += 2;
335  } else if (static_cast<uint8_t>(ch) == 0xe2 && static_cast<uint8_t>(value[i + 1]) == 0x80 &&
336  static_cast<uint8_t>(value[i + 2]) == 0xa9) {
337  out += "\\u2029";
338  i += 2;
339  } else {
340  out += ch;
341  }
342  }
343  out += '"';
344 }

References i.

◆ dump() [5/7]

static void json11::dump ( double  value,
std::string &  out 
)
static

Definition at line 289 of file json11.h.

289  {
290  if (std::isfinite(value)) {
291  char buf[32];
292  snprintf(buf, sizeof buf, "%.17g", value);
293  out += buf;
294  } else {
295  out += "null";
296  }
297 }

◆ dump() [6/7]

static void json11::dump ( long long  value,
std::string &  out 
)
static

Definition at line 299 of file json11.h.

299  {
300  char buf[32];
301  snprintf(buf, sizeof buf, "%lld", value);
302  out += buf;
303 }

◆ dump() [7/7]

static void json11::dump ( NullStruct  ,
std::string &  out 
)
static

Definition at line 285 of file json11.h.

285  {
286  out += "null";
287 }

Referenced by dump(), json11::Value< Json::BOOL, bool >::dump(), and souffle::SparseArray< value_t, 4, merge_op >::dump().

◆ esc()

static std::string json11::esc ( char  c)
inlinestatic

Definition at line 640 of file json11.h.

640  {
641  char buf[12];
642  if (static_cast<uint8_t>(c) >= 0x20 && static_cast<uint8_t>(c) <= 0x7f) {
643  snprintf(buf, sizeof buf, "'%c' (%d)", c, c);
644  } else {
645  snprintf(buf, sizeof buf, "(%d)", c);
646  }
647  return std::string(buf);
648 }

Referenced by json11::Json::parse().

◆ in_range()

static bool json11::in_range ( long  x,
long  lower,
long  upper 
)
inlinestatic

Definition at line 650 of file json11.h.

650  {
651  return (x >= lower && x <= upper);
652 }

◆ parse_multi()

std::vector<Json> json11::parse_multi ( const std::string &  in,
std::string::size_type &  parser_stop_pos,
std::string &  err,
JsonParse  strategy 
)
inline

Definition at line 1087 of file json11.h.

1088  {
1089  JsonParser parser{in, 0, err, false, strategy};
1090  parser_stop_pos = 0;
1091  std::vector<Json> json_vec;
1092  while (parser.i != in.size() && !parser.failed) {
1093  json_vec.push_back(parser.parse_json(0));
1094  if (parser.failed) {
1095  break;
1096  }
1097 
1098  // Check for another object
1099  parser.consume_garbage();
1100  if (parser.failed) {
1101  break;
1102  }
1103  parser_stop_pos = parser.i;
1104  }
1105  return json_vec;
1106 }

References err, and strategy.

◆ static_null()

static const Json& json11::static_null ( )
static

Definition at line 509 of file json11.h.

509  {
510  // This has to be separate, not in Statics, because Json() accesses statics().null.
511  static const Json json_null;
512  return json_null;
513 }

Referenced by json11::JsonValue::operator[](), json11::JsonArray::operator[](), and json11::JsonObject::operator[]().

◆ statics()

static const Statics& json11::statics ( )
static

Definition at line 504 of file json11.h.

504  {
505  static const Statics s{};
506  return s;
507 }

Referenced by json11::JsonValue::array_items(), json11::JsonValue::object_items(), and json11::JsonValue::string_value().

Variable Documentation

◆ max_depth

const int json11::max_depth = 200
static

Definition at line 266 of file json11.h.

err
std::string & err
Definition: json11.h:664
json11::dump
static void dump(const Json::object &values, std::string &out)
Definition: json11.h:357
json11::COMMENTS
@ COMMENTS
Definition: json11.h:83
i
size_t i
Definition: json11.h:663
strategy
const JsonParse strategy
Definition: json11.h:666
json11::STANDARD
@ STANDARD
Definition: json11.h:83