mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 06:58:57 +01:00
Squashed 'src/univalue/' changes from 16a1f7f6e..fe805ea74
fe805ea74 Declare single-argument (non-converting) constructors "explicit" 8a2d6f1e3 Merge pull request #41 from jgarzik/get-obj-map ba341a20d Add getObjMap() helper method. Also, constify checkObject(). ceb119413 Handle .pushKV() and .checkObject() edge cases. 107db9829 Add ::push_back(double) method for feature parity. d41530031 Move one-line implementation of UniValue::read() to header. 52e85b35b Move exception-throwing get_* methods into separate implementation module. dac529675 README.md: update code quotes 3e31dcffb README.md: close code quote d09b8429d Update README.md f1b86edb4 Convert README to markdown style. 1dfe464ef Import UniValue class unit tests from bitcoin project. 0d3e74dd1 operator[] takes size_t index parameter (versus unsigned int) 640158fa2 Private findKey() method becomes size_t clean, and returns bool on failure. 709913585 Merge pull request #36 from ryanofsky/pr/end-str a31231b51 Version 1.0.3 4fd5444d1 Reject unterminated strings 81eba332b Merge pull request #26 from isle2983/pushBackHelpers 36405413e Merge PR #32 from branch 'nul-not-special' of git://github.com/ryanofsky/univalue into merge 89bb07322 Merge pull request #31 from ryanofsky/raw-literals 511008c36 Merge pull request #30 from ryanofsky/test-driver 77974f3a9 Merge pull request #34 from paveljanik/20161116_Wshadow_codepoint a38fcd355 Do not shadow member variable codepoint. fd32d1ab8 Don't require nul-terminated string inputs 0bb1439d0 Support parsing raw literals in UniValue 28876d045 Merge pull request #29 from btcdrak/exportspace 839ccd71f Add test driver for JSONTestSuite 26ef3fff1 Remove trailing whitespace from JSON export cfa0384d6 Convenience wrappers for push_back-ing integer types REVERT: 16a1f7f6e Merge #3: Pull upstream REVERT: daf1285af Merge pull request #2 from jgarzik/master REVERT: f32df99e9 Merge branch '2016_04_unicode' into bitcoin REVERT: 280b191cb Merge remote-tracking branch 'jgarzik/master' into bitcoin REVERT: 2740c4f71 Merge branch '2015_11_escape_plan' into bitcoin git-subtree-dir: src/univalue git-subtree-split: fe805ea74f8919382720b09a905a14e81311b3ad
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#define __UNIVALUE_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
@@ -69,10 +70,11 @@ public:
|
||||
size_t size() const { return values.size(); }
|
||||
|
||||
bool getBool() const { return isTrue(); }
|
||||
bool checkObject(const std::map<std::string,UniValue::VType>& memberTypes);
|
||||
void getObjMap(std::map<std::string,UniValue>& kv) const;
|
||||
bool checkObject(const std::map<std::string,UniValue::VType>& memberTypes) const;
|
||||
const UniValue& operator[](const std::string& key) const;
|
||||
const UniValue& operator[](unsigned int index) const;
|
||||
bool exists(const std::string& key) const { return (findKey(key) >= 0); }
|
||||
const UniValue& operator[](size_t index) const;
|
||||
bool exists(const std::string& key) const { size_t i; return findKey(key, i); }
|
||||
|
||||
bool isNull() const { return (typ == VNULL); }
|
||||
bool isTrue() const { return (typ == VBOOL) && (val == "1"); }
|
||||
@@ -92,8 +94,25 @@ public:
|
||||
std::string s(val_);
|
||||
return push_back(s);
|
||||
}
|
||||
bool push_back(uint64_t val_) {
|
||||
UniValue tmpVal(val_);
|
||||
return push_back(tmpVal);
|
||||
}
|
||||
bool push_back(int64_t val_) {
|
||||
UniValue tmpVal(val_);
|
||||
return push_back(tmpVal);
|
||||
}
|
||||
bool push_back(int val_) {
|
||||
UniValue tmpVal(val_);
|
||||
return push_back(tmpVal);
|
||||
}
|
||||
bool push_back(double val_) {
|
||||
UniValue tmpVal(val_);
|
||||
return push_back(tmpVal);
|
||||
}
|
||||
bool push_backV(const std::vector<UniValue>& vec);
|
||||
|
||||
void __pushKV(const std::string& key, const UniValue& val);
|
||||
bool pushKV(const std::string& key, const UniValue& val);
|
||||
bool pushKV(const std::string& key, const std::string& val_) {
|
||||
UniValue tmpVal(VSTR, val_);
|
||||
@@ -124,9 +143,10 @@ public:
|
||||
std::string write(unsigned int prettyIndent = 0,
|
||||
unsigned int indentLevel = 0) const;
|
||||
|
||||
bool read(const char *raw);
|
||||
bool read(const char *raw, size_t len);
|
||||
bool read(const char *raw) { return read(raw, strlen(raw)); }
|
||||
bool read(const std::string& rawStr) {
|
||||
return read(rawStr.c_str());
|
||||
return read(rawStr.data(), rawStr.size());
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -135,7 +155,7 @@ private:
|
||||
std::vector<std::string> keys;
|
||||
std::vector<UniValue> values;
|
||||
|
||||
int findKey(const std::string& key) const;
|
||||
bool findKey(const std::string& key, size_t& retIdx) const;
|
||||
void writeArray(unsigned int prettyIndent, unsigned int indentLevel, std::string& s) const;
|
||||
void writeObject(unsigned int prettyIndent, unsigned int indentLevel, std::string& s) const;
|
||||
|
||||
@@ -240,7 +260,7 @@ enum jtokentype {
|
||||
};
|
||||
|
||||
extern enum jtokentype getJsonToken(std::string& tokenVal,
|
||||
unsigned int& consumed, const char *raw);
|
||||
unsigned int& consumed, const char *raw, const char *end);
|
||||
extern const char *uvTypeName(UniValue::VType t);
|
||||
|
||||
static inline bool jsonTokenIsValue(enum jtokentype jtt)
|
||||
|
||||
Reference in New Issue
Block a user