Skip to content
This repository was archived by the owner on Jun 17, 2022. It is now read-only.

Pull upstream #4

Merged
merged 28 commits into from
Oct 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
cfa0384
Convenience wrappers for push_back-ing integer types
isle2983 Sep 10, 2016
26ef3ff
Remove trailing whitespace from JSON export
btcdrak Oct 26, 2016
839ccd7
Add test driver for JSONTestSuite
ryanofsky Nov 1, 2016
28876d0
Merge pull request #29 from btcdrak/exportspace
jgarzik Nov 7, 2016
0bb1439
Support parsing raw literals in UniValue
ryanofsky Nov 1, 2016
fd32d1a
Don't require nul-terminated string inputs
ryanofsky Nov 1, 2016
a38fcd3
Do not shadow member variable codepoint.
paveljanik Nov 16, 2016
77974f3
Merge pull request #34 from paveljanik/20161116_Wshadow_codepoint
jgarzik Nov 20, 2016
511008c
Merge pull request #30 from ryanofsky/test-driver
jgarzik Jan 29, 2017
89bb073
Merge pull request #31 from ryanofsky/raw-literals
jgarzik Jan 29, 2017
3640541
Merge PR #32 from branch 'nul-not-special' of git://github.com/ryanof…
jgarzik Jan 29, 2017
81eba33
Merge pull request #26 from isle2983/pushBackHelpers
jgarzik Jan 29, 2017
4fd5444
Reject unterminated strings
ryanofsky Nov 1, 2016
a31231b
Version 1.0.3
jgarzik Jan 29, 2017
7099135
Merge pull request #36 from ryanofsky/pr/end-str
jgarzik Feb 10, 2017
640158f
Private findKey() method becomes size_t clean, and returns bool on fa…
kozyilmaz May 2, 2017
0d3e74d
operator[] takes size_t index parameter (versus unsigned int)
kozyilmaz May 2, 2017
1dfe464
Import UniValue class unit tests from bitcoin project.
jgarzik May 2, 2017
f1b86ed
Convert README to markdown style.
jgarzik May 3, 2017
d09b842
Update README.md
jgarzik May 3, 2017
3e31dcf
README.md: close code quote
jgarzik May 3, 2017
dac5296
README.md: update code quotes
jgarzik May 3, 2017
52e85b3
Move exception-throwing get_* methods into separate implementation mo…
jgarzik May 4, 2017
d415300
Move one-line implementation of UniValue::read() to header.
jgarzik May 5, 2017
107db98
Add ::push_back(double) method for feature parity.
jgarzik May 5, 2017
ceb1194
Handle .pushKV() and .checkObject() edge cases.
jgarzik Aug 3, 2017
ba341a2
Add getObjMap() helper method. Also, constify checkObject().
jgarzik Aug 3, 2017
8a2d6f1
Merge pull request #41 from jgarzik/get-obj-map
jgarzik Sep 24, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pkgconfig_DATA = pc/libunivalue.pc

libunivalue_la_SOURCES = \
lib/univalue.cpp \
lib/univalue_get.cpp \
lib/univalue_read.cpp \
lib/univalue_write.cpp

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

TESTS = test/unitester
TESTS = test/object test/unitester test/no_nul

GENBIN = gen/gen$(BUILD_EXEEXT)
GEN_SRCS = gen/gen.cpp
Expand All @@ -33,7 +34,7 @@ gen: lib/univalue_escapes.h $(GENBIN)
@echo Updating $<
$(AM_V_at)$(GENBIN) > lib/univalue_escapes.h

noinst_PROGRAMS = $(TESTS)
noinst_PROGRAMS = $(TESTS) test/test_json

TEST_DATA_DIR=test

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

test_test_json_SOURCES = test/test_json.cpp
test_test_json_LDADD = libunivalue.la
test_test_json_CXXFLAGS = -I$(top_srcdir)/include
test_test_json_LDFLAGS = -static $(LIBTOOL_APP_LDFLAGS)

test_no_nul_SOURCES = test/no_nul.cpp
test_no_nul_LDADD = libunivalue.la
test_no_nul_CXXFLAGS = -I$(top_srcdir)/include
test_no_nul_LDFLAGS = -static $(LIBTOOL_APP_LDFLAGS)

test_object_SOURCES = test/object.cpp
test_object_LDADD = libunivalue.la
test_object_CXXFLAGS = -I$(top_srcdir)/include
test_object_LDFLAGS = -static $(LIBTOOL_APP_LDFLAGS)

TEST_FILES = \
$(TEST_DATA_DIR)/fail10.json \
$(TEST_DATA_DIR)/fail11.json \
Expand Down Expand Up @@ -77,6 +93,8 @@ TEST_FILES = \
$(TEST_DATA_DIR)/fail39.json \
$(TEST_DATA_DIR)/fail40.json \
$(TEST_DATA_DIR)/fail41.json \
$(TEST_DATA_DIR)/fail42.json \
$(TEST_DATA_DIR)/fail44.json \
$(TEST_DATA_DIR)/fail3.json \
$(TEST_DATA_DIR)/fail4.json \
$(TEST_DATA_DIR)/fail5.json \
Expand All @@ -88,6 +106,11 @@ TEST_FILES = \
$(TEST_DATA_DIR)/pass2.json \
$(TEST_DATA_DIR)/pass3.json \
$(TEST_DATA_DIR)/round1.json \
$(TEST_DATA_DIR)/round2.json
$(TEST_DATA_DIR)/round2.json \
$(TEST_DATA_DIR)/round3.json \
$(TEST_DATA_DIR)/round4.json \
$(TEST_DATA_DIR)/round5.json \
$(TEST_DATA_DIR)/round6.json \
$(TEST_DATA_DIR)/round7.json

EXTRA_DIST=$(TEST_FILES) $(GEN_SRCS)
7 changes: 0 additions & 7 deletions README

This file was deleted.

32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

# UniValue

## Summary

A universal value class, with JSON encoding and decoding.

UniValue is an abstract data type that may be a null, boolean, string,
number, array container, or a key/value dictionary container, nested to
an arbitrary depth.

This class is aligned with the JSON standard, [RFC
7159](https://tools.ietf.org/html/rfc7159.html).

## Installation

This project is a standard GNU
[autotools](https://www.gnu.org/software/automake/manual/html_node/Autotools-Introduction.html)
project. Build and install instructions are available in the `INSTALL`
file provided with GNU autotools.

```
$ ./autogen.sh
$ ./configure
$ make
```

## Design

UniValue provides a single dynamic RAII C++ object class,
and minimizes template use (contra json_spirit).

6 changes: 3 additions & 3 deletions configure.ac
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
m4_define([libunivalue_major_version], [1])
m4_define([libunivalue_minor_version], [1])
m4_define([libunivalue_micro_version], [2])
m4_define([libunivalue_interface_age], [2])
m4_define([libunivalue_micro_version], [3])
m4_define([libunivalue_interface_age], [3])
# If you need a modifier for the version number.
# Normally empty, but can be used to make "fixup" releases.
m4_define([libunivalue_extraversion], [])
Expand All @@ -14,7 +14,7 @@ m4_define([libunivalue_age], [m4_eval(libunivalue_binary_age - libunivalue_inter
m4_define([libunivalue_version], [libunivalue_major_version().libunivalue_minor_version().libunivalue_micro_version()libunivalue_extraversion()])


AC_INIT([univalue], [1.0.2],
AC_INIT([univalue], [1.0.3],
[http://github.com/jgarzik/univalue/])

dnl make the compilation flags quiet unless V=1 is used
Expand Down
34 changes: 27 additions & 7 deletions include/univalue.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#define __UNIVALUE_H__

#include <stdint.h>
#include <string.h>

#include <string>
#include <vector>
Expand Down Expand Up @@ -69,10 +70,11 @@ class UniValue {
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"); }
Expand All @@ -92,8 +94,25 @@ class UniValue {
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_);
Expand Down Expand Up @@ -124,9 +143,10 @@ class UniValue {
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:
Expand All @@ -135,7 +155,7 @@ class UniValue {
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;

Expand Down Expand Up @@ -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)
Expand Down
Loading