GCC Code Coverage Report
Directory: cvmfs/ Exec Total Coverage
File: cvmfs/json_document.h Lines: 3 3 100.0 %
Date: 2019-02-03 02:48:13 Branches: 0 0 - %

Line Branch Exec Source
1
/**
2
 * This file is part of the CernVM File System.
3
 */
4
5
#ifndef CVMFS_JSON_DOCUMENT_H_
6
#define CVMFS_JSON_DOCUMENT_H_
7
8
#include <string>
9
#include <utility>
10
#include <vector>
11
12
#include "json.h"
13
#include "util/single_copy.h"
14
15
typedef struct json_value JSON;
16
typedef std::vector<std::pair<const char *, const char *> > JsonStringInput;
17
18
bool ToJsonString(const JsonStringInput &input, std::string *output);
19
20
class JsonDocument : SingleCopy {
21
 public:
22
  static JsonDocument *Create(const std::string &text);
23
  ~JsonDocument();
24
25
  std::string PrintCanonical();
26
  std::string PrintPretty();
27
28
301
  inline const JSON *root() const { return root_; }
29
6
  inline bool IsValid() const { return root_ != NULL; }
30
31
  static std::string EscapeString(const std::string &input);
32
  static JSON *SearchInObject(const JSON *json_object, const std::string &name,
33
                              const json_type type);
34
35
 private:
36
  static const unsigned kDefaultBlockSize = 2048;  // 2kB
37
38
  struct PrintOptions {
39
3
    PrintOptions() : with_whitespace(false), num_indent(0) {}
40
    bool with_whitespace;
41
    unsigned num_indent;
42
  };
43
44
  JsonDocument();
45
  bool Parse(const std::string &text);
46
  std::string PrintValue(JSON *value, PrintOptions print_options);
47
  std::string PrintArray(JSON *first_child, PrintOptions print_options);
48
  std::string PrintObject(JSON *first_child, PrintOptions print_options);
49
50
  block_allocator allocator_;
51
  JSON *root_;
52
  char *raw_text_;
53
};
54
55
#endif  // CVMFS_JSON_DOCUMENT_H_