File tree Expand file tree Collapse file tree 2 files changed +13
-11
lines changed Expand file tree Collapse file tree 2 files changed +13
-11
lines changed Original file line number Diff line number Diff line change @@ -72,7 +72,7 @@ class UniValue {
72
72
bool checkObject (const std::map<std::string,UniValue::VType>& memberTypes);
73
73
const UniValue& operator [](const std::string& key) const ;
74
74
const UniValue& operator [](unsigned int index) const ;
75
- bool exists (const std::string& key) const { return ( findKey (key) >= 0 ); }
75
+ bool exists (const std::string& key) const { size_t i; return findKey (key, i ); }
76
76
77
77
bool isNull () const { return (typ == VNULL); }
78
78
bool isTrue () const { return (typ == VBOOL) && (val == " 1" ); }
@@ -148,7 +148,7 @@ class UniValue {
148
148
std::vector<std::string> keys;
149
149
std::vector<UniValue> values;
150
150
151
- int findKey (const std::string& key) const ;
151
+ bool findKey (const std::string& key, size_t & retIdx ) const ;
152
152
void writeArray (unsigned int prettyIndent, unsigned int indentLevel, std::string& s) const ;
153
153
void writeObject (unsigned int prettyIndent, unsigned int indentLevel, std::string& s) const ;
154
154
Original file line number Diff line number Diff line change @@ -212,22 +212,24 @@ bool UniValue::pushKVs(const UniValue& obj)
212
212
return true ;
213
213
}
214
214
215
- int UniValue::findKey (const std::string& key) const
215
+ bool UniValue::findKey (const std::string& key, size_t & retIdx ) const
216
216
{
217
- for (unsigned int i = 0 ; i < keys.size (); i++) {
218
- if (keys[i] == key)
219
- return (int ) i;
217
+ for (size_t i = 0 ; i < keys.size (); i++) {
218
+ if (keys[i] == key) {
219
+ retIdx = i;
220
+ return true ;
221
+ }
220
222
}
221
223
222
- return - 1 ;
224
+ return false ;
223
225
}
224
226
225
227
bool UniValue::checkObject (const std::map<std::string,UniValue::VType>& t)
226
228
{
227
229
for (std::map<std::string,UniValue::VType>::const_iterator it = t.begin ();
228
230
it != t.end (); ++it) {
229
- int idx = findKey (it-> first ) ;
230
- if (idx < 0 )
231
+ size_t idx = 0 ;
232
+ if (! findKey (it-> first , idx) )
231
233
return false ;
232
234
233
235
if (values.at (idx).getType () != it->second )
@@ -242,8 +244,8 @@ const UniValue& UniValue::operator[](const std::string& key) const
242
244
if (typ != VOBJ)
243
245
return NullUniValue;
244
246
245
- int index = findKey (key) ;
246
- if (index < 0 )
247
+ size_t index = 0 ;
248
+ if (! findKey (key, index) )
247
249
return NullUniValue;
248
250
249
251
return values.at (index);
You can’t perform that action at this time.
0 commit comments