MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / JSON

Class JSON

base/base/JSON.h:46–193  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

44// NOLINTEND(google-explicit-constructor)
45
46class JSON
47{
48private:
49 using Pos = const char *;
50 Pos ptr_begin{};
51 Pos ptr_end{};
52 unsigned level{};
53
54public:
55 JSON(Pos ptr_begin_, Pos ptr_end_, unsigned level_ = 0) : ptr_begin(ptr_begin_), ptr_end(ptr_end_), level(level_)
56 {
57 checkInit();
58 }
59
60 explicit JSON(std::string_view s) : ptr_begin(s.data()), ptr_end(s.data() + s.size()), level(0)
61 {
62 checkInit();
63 }
64
65 JSON(const JSON & rhs)
66 {
67 *this = rhs;
68 }
69
70 JSON & operator=(const JSON & rhs) = default;
71
72 const char * data() const { return ptr_begin; }
73 const char * dataEnd() const { return ptr_end; }
74
75 enum ElementType : uint8_t
76 {
77 TYPE_OBJECT,
78 TYPE_ARRAY,
79 TYPE_NUMBER,
80 TYPE_STRING,
81 TYPE_BOOL,
82 TYPE_NULL,
83 TYPE_NAME_VALUE_PAIR,
84 TYPE_NOTYPE,
85 };
86
87 ElementType getType() const;
88
89 bool isObject() const { return getType() == TYPE_OBJECT; }
90 bool isArray() const { return getType() == TYPE_ARRAY; }
91 bool isNumber() const { return getType() == TYPE_NUMBER; }
92 bool isString() const { return getType() == TYPE_STRING; }
93 bool isBool() const { return getType() == TYPE_BOOL; }
94 bool isNull() const { return getType() == TYPE_NULL; }
95 bool isNameValuePair() const { return getType() == TYPE_NAME_VALUE_PAIR; }
96
97 /// Number of elements in array or object; if element is not array or object, then exception.
98 size_t size() const;
99
100 /// Whether array or object is empty; if element is not array or object, then exception.
101 bool empty() const;
102
103 /// Get array element by index; if element is not array, then exception.

Callers 10

skipNameValuePairMethod · 0.70
skipArrayMethod · 0.70
skipObjectMethod · 0.70
operator[]Method · 0.70
getValueMethod · 0.70
toDoubleMethod · 0.70
toIntMethod · 0.70
toUIntMethod · 0.70
beginMethod · 0.70
endMethod · 0.70

Calls 1

TFunction · 0.70

Tested by

no test coverage detected