KiCad PCB EDA Suite
json11 Namespace Reference

Classes

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

Functions

static void dump (NullStruct, string &out)
 
static void dump (double value, string &out)
 
static void dump (int value, string &out)
 
static void dump (bool value, string &out)
 
static void dump (const string &value, string &out)
 
static void dump (const Json::array &values, string &out)
 
static void dump (const Json::object &values, string &out)
 
static const Staticsstatics ()
 
static const Json & static_null ()
 
static string esc (char c)
 
static bool in_range (long x, long lower, long upper)
 

Variables

static const int max_depth = 200
 

Function Documentation

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

Definition at line 53 of file json11.cpp.

Referenced by dump(), and json11::Value< Json::STRING, string >::dump().

54 {
55  out += "null";
56 }
static void json11::dump ( double  value,
string &  out 
)
static

Definition at line 59 of file json11.cpp.

60 {
61  if( std::isfinite( value ) )
62  {
63  char buf[32];
64  snprintf( buf, sizeof buf, "%.17g", value );
65  out += buf;
66  }
67  else
68  {
69  out += "null";
70  }
71 }
static void json11::dump ( int  value,
string &  out 
)
static

Definition at line 74 of file json11.cpp.

75 {
76  char buf[32];
77 
78  snprintf( buf, sizeof buf, "%d", value );
79  out += buf;
80 }
static void json11::dump ( bool  value,
string &  out 
)
static

Definition at line 83 of file json11.cpp.

84 {
85  out += value ? "true" : "false";
86 }
static void json11::dump ( const string &  value,
string &  out 
)
static

Definition at line 89 of file json11.cpp.

References i.

90 {
91  out += '"';
92 
93  for( size_t i = 0; i < value.length(); i++ )
94  {
95  const char ch = value[i];
96 
97  if( ch == '\\' )
98  {
99  out += "\\\\";
100  }
101  else if( ch == '"' )
102  {
103  out += "\\\"";
104  }
105  else if( ch == '\b' )
106  {
107  out += "\\b";
108  }
109  else if( ch == '\f' )
110  {
111  out += "\\f";
112  }
113  else if( ch == '\n' )
114  {
115  out += "\\n";
116  }
117  else if( ch == '\r' )
118  {
119  out += "\\r";
120  }
121  else if( ch == '\t' )
122  {
123  out += "\\t";
124  }
125  else if( static_cast<uint8_t>(ch) <= 0x1f )
126  {
127  char buf[8];
128  snprintf( buf, sizeof buf, "\\u%04x", ch );
129  out += buf;
130  }
131  else if( static_cast<uint8_t>(ch) == 0xe2 && static_cast<uint8_t>(value[i + 1]) == 0x80
132  && static_cast<uint8_t>(value[i + 2]) == 0xa8 )
133  {
134  out += "\\u2028";
135  i += 2;
136  }
137  else if( static_cast<uint8_t>(ch) == 0xe2 && static_cast<uint8_t>(value[i + 1]) == 0x80
138  && static_cast<uint8_t>(value[i + 2]) == 0xa9 )
139  {
140  out += "\\u2029";
141  i += 2;
142  }
143  else
144  {
145  out += ch;
146  }
147  }
148 
149  out += '"';
150 }
size_t i
Definition: json11.cpp:597
static void json11::dump ( const Json::array &  values,
string &  out 
)
static

Definition at line 153 of file json11.cpp.

154 {
155  bool first = true;
156 
157  out += "[";
158 
159  for( const auto& value : values )
160  {
161  if( !first )
162  out += ", ";
163 
164  value.dump( out );
165  first = false;
166  }
167 
168  out += "]";
169 }
static void json11::dump ( const Json::object &  values,
string &  out 
)
static

Definition at line 172 of file json11.cpp.

References dump(), and kv.

173 {
174  bool first = true;
175 
176  out += "{";
177 
178  for( const auto& kv : values )
179  {
180  if( !first )
181  out += ", ";
182 
183  dump( kv.first, out );
184  out += ": ";
185  kv.second.dump( out );
186  first = false;
187  }
188 
189  out += "}";
190 }
static void dump(const Json::object &values, string &out)
Definition: json11.cpp:172
#define kv
static string json11::esc ( char  c)
inlinestatic

Definition at line 564 of file json11.cpp.

565 {
566  char buf[12];
567 
568  if( static_cast<uint8_t>(c) >= 0x20 && static_cast<uint8_t>(c) <= 0x7f )
569  {
570  snprintf( buf, sizeof buf, "'%c' (%d)", c, c );
571  }
572  else
573  {
574  snprintf( buf, sizeof buf, "(%d)", c );
575  }
576 
577  return string( buf );
578 }
static bool json11::in_range ( long  x,
long  lower,
long  upper 
)
inlinestatic

Definition at line 581 of file json11.cpp.

Referenced by TRACK_WIDTH_MENU::eventHandler().

582 {
583  return x >= lower && x <= upper;
584 }
static const Json& json11::static_null ( )
static

Definition at line 332 of file json11.cpp.

References json11::Statics::empty_map, json11::Statics::empty_string, json11::Statics::empty_vector, i, and statics().

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

333 {
334  // This has to be separate, not in Statics, because Json() accesses statics().null.
335  static const Json json_null;
336 
337  return json_null;
338 }
static const Statics& json11::statics ( )
static

Definition at line 324 of file json11.cpp.

Referenced by static_null().

325 {
326  static const Statics s {};
327 
328  return s;
329 }

Variable Documentation

const int json11::max_depth = 200
static

Definition at line 30 of file json11.cpp.