20 bool retval = json->
Parse(text);
21 if (!retval)
return NULL;
27 escaped.reserve(input.length());
29 for (
unsigned i = 0, s = input.length(); i < s; ++i) {
30 if (input[i] ==
'\\') {
31 escaped.push_back(
'\\');
32 escaped.push_back(
'\\');
33 }
else if (input[i] ==
'"') {
34 escaped.push_back(
'\\');
35 escaped.push_back(
'"');
37 escaped.push_back(input[i]);
44 : allocator_(kDefaultBlockSize), root_(NULL), raw_text_(NULL) {}
72 "Failed to parse json string. Error at line %d: %s (%s)",
73 error_line, error_desc, error_pos);
87 JSON *value = first_child;
90 value = value->next_sibling;
92 while (value != NULL) {
95 value = value->next_sibling;
99 for (
unsigned i = 2; i < print_options.
num_indent; ++i)
100 result.push_back(
' ');
113 if (!
root_)
return "";
125 JSON *value = first_child;
128 value = value->next_sibling;
130 while (value != NULL) {
133 value = value->next_sibling;
137 for (
unsigned i = 2; i < print_options.
num_indent; ++i)
138 result.push_back(
' ');
147 if (!
root_)
return "";
157 for (
unsigned i = 0; i < print_options.
num_indent; ++i) result.push_back(
' ');
162 switch (value->type) {
167 result +=
PrintObject(value->first_child, print_options);
170 result +=
PrintArray(value->first_child, print_options);
173 result +=
"\"" +
EscapeString(value->string_value) +
"\"";
182 result += value->int_value ?
"true" :
"false";
191 const json_type
type) {
192 if (!json_object || (json_object->type != JSON_OBJECT))
return NULL;
194 JSON *walker = json_object->first_child;
195 while (walker != NULL) {
196 if (
string(walker->name) == name) {
197 return (walker->type == type) ? walker : NULL;
199 walker = walker->next_sibling;
205 bool GetFromJSON<std::string>(
const JSON *object,
const std::string &name,
206 std::string *value) {
214 *value = o->string_value;
224 if (o == NULL || value == NULL) {
228 *value = o->int_value;
238 if (o == NULL || value == NULL) {
242 *value = o->float_value;
block_allocator allocator_
#define LogCvmfs(source, mask,...)
std::string PrintValue(JSON *value, PrintOptions print_options)
std::string PrintObject(JSON *first_child, PrintOptions print_options)
static JSON * SearchInObject(const JSON *json_object, const std::string &name, const json_type type)
std::string PrintArray(JSON *first_child, PrintOptions print_options)
bool Parse(const std::string &text)
assert((mem||(size==0))&&"Out Of Memory")
string StringifyDouble(const double value)
std::string PrintCanonical()
std::string PrintPretty()
static JsonDocument * Create(const std::string &text)
string StringifyInt(const int64_t value)
static std::string EscapeString(const std::string &input)
bool GetFromJSON< int >(const JSON *object, const std::string &name, int *value)
bool GetFromJSON< float >(const JSON *object, const std::string &name, float *value)
const JSON * root() const