7
7
#define __UNIVALUE_H__
8
8
9
9
#include < stdint.h>
10
+ #include < string.h>
10
11
11
12
#include < string>
12
13
#include < vector>
@@ -69,10 +70,11 @@ class UniValue {
69
70
size_t size () const { return values.size (); }
70
71
71
72
bool getBool () const { return isTrue (); }
72
- bool checkObject (const std::map<std::string,UniValue::VType>& memberTypes);
73
+ void getObjMap (std::map<std::string,UniValue>& kv) const ;
74
+ bool checkObject (const std::map<std::string,UniValue::VType>& memberTypes) const ;
73
75
const UniValue& operator [](const std::string& key) const ;
74
- const UniValue& operator [](unsigned int index) const ;
75
- bool exists (const std::string& key) const { return ( findKey (key) >= 0 ); }
76
+ const UniValue& operator [](size_t index) const ;
77
+ bool exists (const std::string& key) const { size_t i; return findKey (key, i ); }
76
78
77
79
bool isNull () const { return (typ == VNULL); }
78
80
bool isTrue () const { return (typ == VBOOL) && (val == " 1" ); }
@@ -92,8 +94,25 @@ class UniValue {
92
94
std::string s (val_);
93
95
return push_back (s);
94
96
}
97
+ bool push_back (uint64_t val_) {
98
+ UniValue tmpVal (val_);
99
+ return push_back (tmpVal);
100
+ }
101
+ bool push_back (int64_t val_) {
102
+ UniValue tmpVal (val_);
103
+ return push_back (tmpVal);
104
+ }
105
+ bool push_back (int val_) {
106
+ UniValue tmpVal (val_);
107
+ return push_back (tmpVal);
108
+ }
109
+ bool push_back (double val_) {
110
+ UniValue tmpVal (val_);
111
+ return push_back (tmpVal);
112
+ }
95
113
bool push_backV (const std::vector<UniValue>& vec);
96
114
115
+ void __pushKV (const std::string& key, const UniValue& val);
97
116
bool pushKV (const std::string& key, const UniValue& val);
98
117
bool pushKV (const std::string& key, const std::string& val_) {
99
118
UniValue tmpVal (VSTR, val_);
@@ -124,9 +143,10 @@ class UniValue {
124
143
std::string write (unsigned int prettyIndent = 0 ,
125
144
unsigned int indentLevel = 0 ) const ;
126
145
127
- bool read (const char *raw);
146
+ bool read (const char *raw, size_t len);
147
+ bool read (const char *raw) { return read (raw, strlen (raw)); }
128
148
bool read (const std::string& rawStr) {
129
- return read (rawStr.c_str ());
149
+ return read (rawStr.data (), rawStr. size ());
130
150
}
131
151
132
152
private:
@@ -135,7 +155,7 @@ class UniValue {
135
155
std::vector<std::string> keys;
136
156
std::vector<UniValue> values;
137
157
138
- int findKey (const std::string& key) const ;
158
+ bool findKey (const std::string& key, size_t & retIdx ) const ;
139
159
void writeArray (unsigned int prettyIndent, unsigned int indentLevel, std::string& s) const ;
140
160
void writeObject (unsigned int prettyIndent, unsigned int indentLevel, std::string& s) const ;
141
161
@@ -240,7 +260,7 @@ enum jtokentype {
240
260
};
241
261
242
262
extern enum jtokentype getJsonToken (std::string& tokenVal,
243
- unsigned int & consumed, const char *raw);
263
+ unsigned int & consumed, const char *raw, const char *end );
244
264
extern const char *uvTypeName (UniValue::VType t);
245
265
246
266
static inline bool jsonTokenIsValue (enum jtokentype jtt)
0 commit comments