Skip to content

Commit eeda9f9

Browse files
add ULib
1 parent a00d4eb commit eeda9f9

File tree

6 files changed

+187
-0
lines changed

6 files changed

+187
-0
lines changed

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,6 @@
116116
[submodule "thirdparty/juson"]
117117
path = thirdparty/juson
118118
url = https://github.com/wgtdkp/juson.git
119+
[submodule "thirdparty/ULib"]
120+
path = thirdparty/ULib
121+
url = https://github.com/stefanocasazza/ULib

.travis.yml

+6
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,11 @@ install:
7474
- if [ "$CXX" = "g++" ]; then export CXX="g++-5" CC="gcc-5"; fi
7575
- if [ "$CXX" = "clang++" ]; then export CXX="clang++-3.7" CC="clang-3.7"; fi
7676

77+
before_script:
78+
- cd ${TRAVIS_BUILD_DIR}/thirdparty/ULib
79+
- ./configure --disable-shared
80+
- make
81+
- cd ${TRAVIS_BUILD_DIR}
82+
7783
script:
7884
- make CONFIG=$CONFIG

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ udp/json | C | 1.1.0 | Actually 2 libraries: [udp/json-parser](https://github.co
101101
[V8](https://github.com/v8/v8) | C++ | 5.1.281.47 | Need installation |
102102
[vincenthz/libjson](https://github.com/vincenthz/libjson) | C | 0.8
103103
[YAJL](https://github.com/lloyd/yajl) | C | 2.1.0
104+
[ULib](https://github.com/stefanocasazza/ULib/tree/master) | C++ | v1.4.2 | Need building: (./configure --disable-shared && make) |
104105

105106
Libraries with Git repository are included as submodule in `thirdparty` path. Other libraries are add as files in `thirdparty` path.
106107

build/premake5.lua

+6
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,11 @@ solution "benchmark"
128128
"../thirdparty/include/jeayeson/include/dummy",
129129
"../thirdparty/jvar/include",
130130
"../thirdparty/pjson/inc",
131+
"../thirdparty/ULib/include",
131132
}
132133

134+
linkoptions { "../../thirdparty/ULib/src/ulib/.libs/libulib.a" }
135+
133136
files {
134137
"../src/*.h",
135138
"../src/*.cpp",
@@ -181,6 +184,7 @@ solution "jsonstat"
181184
"../thirdparty/include/jeayeson/include/dummy",
182185
"../thirdparty/jvar/include",
183186
"../thirdparty/pjson/inc",
187+
"../thirdparty/ULib/include",
184188
}
185189

186190
configuration "release"
@@ -224,6 +228,8 @@ solution "jsonstat"
224228
links "jsonclibs2"
225229
setTargetObjDir("../bin/jsonstat")
226230

231+
linkoptions { "../../thirdparty/ULib/src/ulib/.libs/libulib.a" }
232+
227233
configuration "gmake"
228234
buildoptions "-std=c++14"
229235
end

src/tests/ULibtest.cpp

+170
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
#include "../test.h"
2+
3+
/**
4+
* NB: if ULib is configured and compiled (./configure --disable-shared && make) use this way:
5+
*
6+
* #define HAVE_CONFIG_H
7+
* #include <ulib/json/value.h>
8+
* #undef HAVE_CONFIG_H
9+
*
10+
* otherwise:
11+
*
12+
* #include <ULib/src/ulib/all_cpp.cpp>
13+
*/
14+
15+
#define HAVE_CONFIG_H
16+
#include <ulib/json/value.h>
17+
#undef HAVE_CONFIG_H
18+
19+
static ULib ulib("167193,0,0,0,-30,-31,-30,-31,0");
20+
21+
static void GenStat(Stat& stat, const union UValue::jval val)
22+
{
23+
U_TRACE(5, "::GenStat(%p,0x%x)", &stat, val.ival)
24+
25+
switch (UValue::getTag(val.ival))
26+
{
27+
case UValue::REAL_VALUE:
28+
case UValue::INT_VALUE:
29+
case UValue::UINT_VALUE: stat.numberCount++; break;
30+
case UValue::TRUE_VALUE: stat.trueCount++; break;
31+
case UValue::FALSE_VALUE: stat.falseCount++; break;
32+
case UValue::NULL_VALUE: stat.nullCount++; break;
33+
34+
case UValue::STRING_VALUE:
35+
case UValue::UTF_VALUE:
36+
{
37+
stat.stringCount++;
38+
39+
stat.stringLength += UValue::getStringSize(val);
40+
}
41+
break;
42+
43+
case UValue::ARRAY_VALUE:
44+
{
45+
stat.arrayCount++;
46+
47+
for (auto const& i : val)
48+
{
49+
stat.elementCount++;
50+
51+
GenStat(stat, i.getValue());
52+
}
53+
}
54+
break;
55+
56+
case UValue::OBJECT_VALUE:
57+
{
58+
stat.objectCount++;
59+
60+
for (auto const& i : val)
61+
{
62+
stat.memberCount++;
63+
stat.stringCount++; // Key
64+
stat.stringLength += UValue::getStringSize(i.getKey());
65+
66+
GenStat(stat, i.getValue());
67+
}
68+
}
69+
break;
70+
}
71+
}
72+
73+
class ULibParseResult : public ParseResultBase {
74+
public:
75+
UString s;
76+
UValue json;
77+
};
78+
79+
class ULibStringResult : public StringResultBase {
80+
public:
81+
virtual const char* c_str() const { return s.data(); }
82+
83+
UString s;
84+
};
85+
86+
class ULibTest : public TestBase {
87+
public:
88+
#if TEST_INFO
89+
virtual const char* GetName() const { return "ULib (C++)"; }
90+
virtual const char* GetFilename() const { return __FILE__; }
91+
#endif
92+
93+
#if TEST_PARSE
94+
virtual ParseResultBase* Parse(const char* json, size_t length) const
95+
{
96+
ULibParseResult* pr = new ULibParseResult;
97+
98+
return (pr->json.parse((pr->s = UString(json, length))) ? pr : (delete pr, (ULibParseResult*)0));
99+
}
100+
#endif
101+
102+
#if TEST_STRINGIFY
103+
virtual StringResultBase* Stringify(const ParseResultBase* parseResult) const
104+
{
105+
ULibStringResult* sr = new ULibStringResult;
106+
107+
sr->s = ((const ULibParseResult*)parseResult)->json.output();
108+
109+
return sr;
110+
}
111+
#endif
112+
113+
#if TEST_PRETTIFY
114+
virtual StringResultBase* Prettify(const ParseResultBase* parseResult) const
115+
{
116+
ULibStringResult* sr = new ULibStringResult;
117+
118+
sr->s = ((const ULibParseResult*)parseResult)->json.prettify();
119+
120+
return sr;
121+
}
122+
#endif
123+
124+
#if TEST_STATISTICS
125+
virtual bool Statistics(const ParseResultBase* parseResult, Stat* stat) const
126+
{
127+
(void) memset(stat, 0, sizeof(Stat));
128+
129+
const ULibParseResult* pr = static_cast<const ULibParseResult*>(parseResult);
130+
131+
GenStat(*stat, pr->json.getValue());
132+
133+
return true;
134+
}
135+
#endif
136+
137+
#if TEST_CONFORMANCE
138+
virtual bool ParseDouble(const char* json, double* d) const
139+
{
140+
UValue v;
141+
142+
if (v.parse(UString(json)))
143+
{
144+
*d = v.at(0)->getDouble();
145+
146+
return true;
147+
}
148+
149+
return false;
150+
}
151+
152+
virtual bool ParseString(const char* json, std::string& s) const
153+
{
154+
UValue v;
155+
156+
if (v.parse(UString(json)))
157+
{
158+
UString result = v.at(0)->getString();
159+
160+
(void) s.assign(U_STRING_TO_PARAM(result));
161+
162+
return true;
163+
}
164+
165+
return false;
166+
}
167+
#endif
168+
};
169+
170+
REGISTER_TEST(ULibTest);

thirdparty/ULib

Submodule ULib added at 568419a

0 commit comments

Comments
 (0)