Skip to content

Commit 619bb05

Browse files
author
MarcoFalke
committed
Squashed 'src/univalue/' changes from 16a1f7f..fe805ea
fe805ea Declare single-argument (non-converting) constructors "explicit" 8a2d6f1 Merge pull request bitcoin#41 from jgarzik/get-obj-map ba341a2 Add getObjMap() helper method. Also, constify checkObject(). ceb1194 Handle .pushKV() and .checkObject() edge cases. 107db98 Add ::push_back(double) method for feature parity. d415300 Move one-line implementation of UniValue::read() to header. 52e85b3 Move exception-throwing get_* methods into separate implementation module. dac5296 README.md: update code quotes 3e31dcf README.md: close code quote d09b842 Update README.md f1b86ed Convert README to markdown style. 1dfe464 Import UniValue class unit tests from bitcoin project. 0d3e74d operator[] takes size_t index parameter (versus unsigned int) 640158f Private findKey() method becomes size_t clean, and returns bool on failure. 7099135 Merge pull request bitcoin#36 from ryanofsky/pr/end-str a31231b Version 1.0.3 4fd5444 Reject unterminated strings 81eba33 Merge pull request bitcoin#26 from isle2983/pushBackHelpers 3640541 Merge PR bitcoin#32 from branch 'nul-not-special' of git://github.com/ryanofsky/univalue into merge 89bb073 Merge pull request bitcoin#31 from ryanofsky/raw-literals 511008c Merge pull request bitcoin#30 from ryanofsky/test-driver 77974f3 Merge pull request bitcoin#34 from paveljanik/20161116_Wshadow_codepoint a38fcd3 Do not shadow member variable codepoint. fd32d1a Don't require nul-terminated string inputs 0bb1439 Support parsing raw literals in UniValue 28876d0 Merge pull request bitcoin#29 from btcdrak/exportspace 839ccd7 Add test driver for JSONTestSuite 26ef3ff Remove trailing whitespace from JSON export cfa0384 Convenience wrappers for push_back-ing integer types REVERT: 16a1f7f Merge #3: Pull upstream REVERT: daf1285 Merge pull request #2 from jgarzik/master REVERT: f32df99 Merge branch '2016_04_unicode' into bitcoin REVERT: 280b191 Merge remote-tracking branch 'jgarzik/master' into bitcoin REVERT: 2740c4f Merge branch '2015_11_escape_plan' into bitcoin git-subtree-dir: src/univalue git-subtree-split: fe805ea
1 parent 2ca7faa commit 619bb05

23 files changed

+783
-229
lines changed

Makefile.am

+26-3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ pkgconfig_DATA = pc/libunivalue.pc
1212

1313
libunivalue_la_SOURCES = \
1414
lib/univalue.cpp \
15+
lib/univalue_get.cpp \
1516
lib/univalue_read.cpp \
1617
lib/univalue_write.cpp
1718

@@ -20,7 +21,7 @@ libunivalue_la_LDFLAGS = \
2021
-no-undefined
2122
libunivalue_la_CXXFLAGS = -I$(top_srcdir)/include
2223

23-
TESTS = test/unitester
24+
TESTS = test/object test/unitester test/no_nul
2425

2526
GENBIN = gen/gen$(BUILD_EXEEXT)
2627
GEN_SRCS = gen/gen.cpp
@@ -33,7 +34,7 @@ gen: lib/univalue_escapes.h $(GENBIN)
3334
@echo Updating $<
3435
$(AM_V_at)$(GENBIN) > lib/univalue_escapes.h
3536

36-
noinst_PROGRAMS = $(TESTS)
37+
noinst_PROGRAMS = $(TESTS) test/test_json
3738

3839
TEST_DATA_DIR=test
3940

@@ -42,6 +43,21 @@ test_unitester_LDADD = libunivalue.la
4243
test_unitester_CXXFLAGS = -I$(top_srcdir)/include -DJSON_TEST_SRC=\"$(srcdir)/$(TEST_DATA_DIR)\"
4344
test_unitester_LDFLAGS = -static $(LIBTOOL_APP_LDFLAGS)
4445

46+
test_test_json_SOURCES = test/test_json.cpp
47+
test_test_json_LDADD = libunivalue.la
48+
test_test_json_CXXFLAGS = -I$(top_srcdir)/include
49+
test_test_json_LDFLAGS = -static $(LIBTOOL_APP_LDFLAGS)
50+
51+
test_no_nul_SOURCES = test/no_nul.cpp
52+
test_no_nul_LDADD = libunivalue.la
53+
test_no_nul_CXXFLAGS = -I$(top_srcdir)/include
54+
test_no_nul_LDFLAGS = -static $(LIBTOOL_APP_LDFLAGS)
55+
56+
test_object_SOURCES = test/object.cpp
57+
test_object_LDADD = libunivalue.la
58+
test_object_CXXFLAGS = -I$(top_srcdir)/include
59+
test_object_LDFLAGS = -static $(LIBTOOL_APP_LDFLAGS)
60+
4561
TEST_FILES = \
4662
$(TEST_DATA_DIR)/fail10.json \
4763
$(TEST_DATA_DIR)/fail11.json \
@@ -77,6 +93,8 @@ TEST_FILES = \
7793
$(TEST_DATA_DIR)/fail39.json \
7894
$(TEST_DATA_DIR)/fail40.json \
7995
$(TEST_DATA_DIR)/fail41.json \
96+
$(TEST_DATA_DIR)/fail42.json \
97+
$(TEST_DATA_DIR)/fail44.json \
8098
$(TEST_DATA_DIR)/fail3.json \
8199
$(TEST_DATA_DIR)/fail4.json \
82100
$(TEST_DATA_DIR)/fail5.json \
@@ -88,6 +106,11 @@ TEST_FILES = \
88106
$(TEST_DATA_DIR)/pass2.json \
89107
$(TEST_DATA_DIR)/pass3.json \
90108
$(TEST_DATA_DIR)/round1.json \
91-
$(TEST_DATA_DIR)/round2.json
109+
$(TEST_DATA_DIR)/round2.json \
110+
$(TEST_DATA_DIR)/round3.json \
111+
$(TEST_DATA_DIR)/round4.json \
112+
$(TEST_DATA_DIR)/round5.json \
113+
$(TEST_DATA_DIR)/round6.json \
114+
$(TEST_DATA_DIR)/round7.json
92115

93116
EXTRA_DIST=$(TEST_FILES) $(GEN_SRCS)

README

-7
This file was deleted.

README.md

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
# UniValue
3+
4+
## Summary
5+
6+
A universal value class, with JSON encoding and decoding.
7+
8+
UniValue is an abstract data type that may be a null, boolean, string,
9+
number, array container, or a key/value dictionary container, nested to
10+
an arbitrary depth.
11+
12+
This class is aligned with the JSON standard, [RFC
13+
7159](https://tools.ietf.org/html/rfc7159.html).
14+
15+
## Installation
16+
17+
This project is a standard GNU
18+
[autotools](https://www.gnu.org/software/automake/manual/html_node/Autotools-Introduction.html)
19+
project. Build and install instructions are available in the `INSTALL`
20+
file provided with GNU autotools.
21+
22+
```
23+
$ ./autogen.sh
24+
$ ./configure
25+
$ make
26+
```
27+
28+
## Design
29+
30+
UniValue provides a single dynamic RAII C++ object class,
31+
and minimizes template use (contra json_spirit).
32+

configure.ac

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
m4_define([libunivalue_major_version], [1])
22
m4_define([libunivalue_minor_version], [1])
3-
m4_define([libunivalue_micro_version], [2])
4-
m4_define([libunivalue_interface_age], [2])
3+
m4_define([libunivalue_micro_version], [3])
4+
m4_define([libunivalue_interface_age], [3])
55
# If you need a modifier for the version number.
66
# Normally empty, but can be used to make "fixup" releases.
77
m4_define([libunivalue_extraversion], [])
@@ -14,7 +14,7 @@ m4_define([libunivalue_age], [m4_eval(libunivalue_binary_age - libunivalue_inter
1414
m4_define([libunivalue_version], [libunivalue_major_version().libunivalue_minor_version().libunivalue_micro_version()libunivalue_extraversion()])
1515

1616

17-
AC_INIT([univalue], [1.0.2],
17+
AC_INIT([univalue], [1.0.3],
1818
[http://github.com/jgarzik/univalue/])
1919

2020
dnl make the compilation flags quiet unless V=1 is used

include/univalue.h

+27-7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#define __UNIVALUE_H__
88

99
#include <stdint.h>
10+
#include <string.h>
1011

1112
#include <string>
1213
#include <vector>
@@ -69,10 +70,11 @@ class UniValue {
6970
size_t size() const { return values.size(); }
7071

7172
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;
7375
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); }
7678

7779
bool isNull() const { return (typ == VNULL); }
7880
bool isTrue() const { return (typ == VBOOL) && (val == "1"); }
@@ -92,8 +94,25 @@ class UniValue {
9294
std::string s(val_);
9395
return push_back(s);
9496
}
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+
}
95113
bool push_backV(const std::vector<UniValue>& vec);
96114

115+
void __pushKV(const std::string& key, const UniValue& val);
97116
bool pushKV(const std::string& key, const UniValue& val);
98117
bool pushKV(const std::string& key, const std::string& val_) {
99118
UniValue tmpVal(VSTR, val_);
@@ -124,9 +143,10 @@ class UniValue {
124143
std::string write(unsigned int prettyIndent = 0,
125144
unsigned int indentLevel = 0) const;
126145

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)); }
128148
bool read(const std::string& rawStr) {
129-
return read(rawStr.c_str());
149+
return read(rawStr.data(), rawStr.size());
130150
}
131151

132152
private:
@@ -135,7 +155,7 @@ class UniValue {
135155
std::vector<std::string> keys;
136156
std::vector<UniValue> values;
137157

138-
int findKey(const std::string& key) const;
158+
bool findKey(const std::string& key, size_t& retIdx) const;
139159
void writeArray(unsigned int prettyIndent, unsigned int indentLevel, std::string& s) const;
140160
void writeObject(unsigned int prettyIndent, unsigned int indentLevel, std::string& s) const;
141161

@@ -240,7 +260,7 @@ enum jtokentype {
240260
};
241261

242262
extern enum jtokentype getJsonToken(std::string& tokenVal,
243-
unsigned int& consumed, const char *raw);
263+
unsigned int& consumed, const char *raw, const char *end);
244264
extern const char *uvTypeName(UniValue::VType t);
245265

246266
static inline bool jsonTokenIsValue(enum jtokentype jtt)

0 commit comments

Comments
 (0)