Khem khem
This commit is contained in:
parent
d4c48ea269
commit
fadf87c0d2
2
.gitignore
vendored
2
.gitignore
vendored
@ -9,4 +9,4 @@ building/*.png
|
|||||||
building/*.svg
|
building/*.svg
|
||||||
|
|
||||||
.idea/
|
.idea/
|
||||||
|
local.sh
|
||||||
|
@ -69,7 +69,7 @@ struct TestWebsiteBuildScript {
|
|||||||
};
|
};
|
||||||
for (std::string& u: T.exported_headers)
|
for (std::string& u: T.exported_headers)
|
||||||
u = "jsonincpp/" + u;
|
u = "jsonincpp/" + u;
|
||||||
T.installation_dir = "";
|
T.installation_dir = "json";
|
||||||
my_targets.push_back(T);
|
my_targets.push_back(T);
|
||||||
}
|
}
|
||||||
if (make_tests) { CTarget T{"libjsonincpp_test0", "executable"};
|
if (make_tests) { CTarget T{"libjsonincpp_test0", "executable"};
|
||||||
|
@ -29,6 +29,11 @@ namespace json {
|
|||||||
struct JSON_reference;
|
struct JSON_reference;
|
||||||
struct JSON_reference_const;
|
struct JSON_reference_const;
|
||||||
|
|
||||||
|
struct JSON;
|
||||||
|
|
||||||
|
typedef std::vector<JSON> jarr;
|
||||||
|
typedef std::map<std::string, JSON> jdict;
|
||||||
|
|
||||||
struct JSON {
|
struct JSON {
|
||||||
void* value = NULL;
|
void* value = NULL;
|
||||||
json_t type = null_symbol;
|
json_t type = null_symbol;
|
||||||
|
@ -83,18 +83,34 @@ namespace json {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Integer & JSON::asInteger() {
|
Integer & JSON::asInteger() {
|
||||||
|
if (isNull()) {
|
||||||
|
value = new Integer();
|
||||||
|
type = integer;
|
||||||
|
}
|
||||||
return const_cast<Integer&>(const_cast<const JSON*>(this)->asInteger());
|
return const_cast<Integer&>(const_cast<const JSON*>(this)->asInteger());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string &JSON::asString() {
|
std::string &JSON::asString() {
|
||||||
|
if (isNull()) {
|
||||||
|
value = new std::string();
|
||||||
|
type = string;
|
||||||
|
}
|
||||||
return const_cast<std::string&>(const_cast<const JSON*>(this)->asString());
|
return const_cast<std::string&>(const_cast<const JSON*>(this)->asString());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<JSON> &JSON::asArray() {
|
std::vector<JSON> &JSON::asArray() {
|
||||||
|
if (isNull()) {
|
||||||
|
value = new ArrayData();
|
||||||
|
type = array;
|
||||||
|
}
|
||||||
return const_cast<std::vector<JSON>&>(const_cast<const JSON*>(this)->asArray());
|
return const_cast<std::vector<JSON>&>(const_cast<const JSON*>(this)->asArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::map<std::string, JSON> &JSON::asDictionary() {
|
std::map<std::string, JSON> &JSON::asDictionary() {
|
||||||
|
if (isNull()) {
|
||||||
|
value = new DictionaryData();
|
||||||
|
type = dictionary;
|
||||||
|
}
|
||||||
return const_cast<std::map<std::string, JSON>&>(const_cast<const JSON*>(this)->asDictionary());
|
return const_cast<std::map<std::string, JSON>&>(const_cast<const JSON*>(this)->asDictionary());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,12 +34,17 @@ void test_obvious(const JSON& A) {
|
|||||||
test(*big[0], *big[1], true);
|
test(*big[0], *big[1], true);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
void ftest(int i) {
|
||||||
json::JSON cba;
|
JSON A;
|
||||||
cba["boba"] = json::JSON("<>");
|
JSON B;
|
||||||
printf("%s\n", generate_str(cba["boba"].g(), print_compact).c_str());
|
A["aaa"][(size_t)i]["bbb"].g().asArray().push_back(JSON(jarr{JSON(""), JSON("")}));
|
||||||
// return 0;
|
// B.asDictionary().
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
for (int i = 0; i < 1000; i++) {
|
||||||
|
ftest(i);
|
||||||
|
}
|
||||||
test_obvious(parse_str_flawless("{ \"aaa\": true, \"2\":[true]}"));
|
test_obvious(parse_str_flawless("{ \"aaa\": true, \"2\":[true]}"));
|
||||||
test_obvious(parse_str_flawless("{ \"aa\": true, \"tttt\": [true, false]}"));
|
test_obvious(parse_str_flawless("{ \"aa\": true, \"tttt\": [true, false]}"));
|
||||||
test_obvious(parse_str_flawless("[[[]]]"));
|
test_obvious(parse_str_flawless("[[[]]]"));
|
||||||
|
Loading…
Reference in New Issue
Block a user