20 bool retval = json->
Parse(text);
28 escaped.reserve(input.length());
30 for (
unsigned i = 0, s = input.length(); i < s; ++i) {
31 if (input[i] ==
'\\') {
32 escaped.push_back(
'\\');
33 escaped.push_back(
'\\');
34 }
else if (input[i] ==
'"') {
35 escaped.push_back(
'\\');
36 escaped.push_back(
'"');
38 escaped.push_back(input[i]);
45 : allocator_(kDefaultBlockSize), root_(NULL), raw_text_(NULL) { }
74 "Failed to parse json string. Error at line %d: %s (%s)",
75 error_line, error_desc, error_pos);
89 JSON *value = first_child;
92 value = value->next_sibling;
94 while (value != NULL) {
97 value = value->next_sibling;
101 for (
unsigned i = 2; i < print_options.
num_indent; ++i)
102 result.push_back(
' ');
128 JSON *value = first_child;
131 value = value->next_sibling;
133 while (value != NULL) {
136 value = value->next_sibling;
140 for (
unsigned i = 2; i < print_options.
num_indent; ++i)
141 result.push_back(
' ');
161 for (
unsigned i = 0; i < print_options.
num_indent; ++i)
162 result.push_back(
' ');
168 switch (value->type) {
173 result +=
PrintObject(value->first_child, print_options);
176 result +=
PrintArray(value->first_child, print_options);
179 result +=
"\"" +
EscapeString(value->string_value) +
"\"";
188 result += value->int_value ?
"true" :
"false";
197 const json_type
type) {
198 if (!json_object || (json_object->type != JSON_OBJECT))
201 JSON *walker = json_object->first_child;
202 while (walker != NULL) {
203 if (
string(walker->name) == name) {
204 return (walker->type == type) ? walker : NULL;
206 walker = walker->next_sibling;
212 bool GetFromJSON<std::string>(
const JSON *object,
const std::string &name,
213 std::string *value) {
221 *value = o->string_value;
231 if (o == NULL || value == NULL) {
235 *value = o->int_value;
245 if (o == NULL || value == NULL) {
249 *value = o->float_value;
block_allocator allocator_
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
CVMFS_EXPORT void LogCvmfs(const LogSource source, const int mask, const char *format,...)