mirror of
https://github.com/simdjson/simdjson
synced 2026-06-08 17:27:07 +00:00
Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4b13020d65 | |||
| 75c6c950e5 | |||
| 5ad7698af1 | |||
| f6f359d3eb | |||
| 185e157e0c | |||
| 3f3f6cde7c | |||
| 005054916d | |||
| 338224849d | |||
| ada52641b4 | |||
| ede9d57f22 |
@@ -0,0 +1,24 @@
|
||||
name: Ubuntu 22.04 CI GCC 12 with GLIBCXX_ASSERTIONS
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
ubuntu-build:
|
||||
if: >-
|
||||
! contains(toJSON(github.event.commits.*.message), '[skip ci]') &&
|
||||
! contains(toJSON(github.event.commits.*.message), '[skip github]')
|
||||
runs-on: ubuntu-22.04
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/cache@v3
|
||||
with:
|
||||
path: dependencies/.cache
|
||||
key: ${{ hashFiles('dependencies/CMakeLists.txt') }}
|
||||
- name: Install gcc12
|
||||
run: sudo apt-get install -y g++-12
|
||||
- name: Use cmake
|
||||
run: |
|
||||
mkdir build &&
|
||||
cd build &&
|
||||
CXX=g++-12 cmake -DCMAKE_BUILD_TYPE=Debug -DSIMDJSON_GLIBCXX_ASSERTIONS=ON -DSIMDJSON_GOOGLE_BENCHMARKS=OFF -DSIMDJSON_DEVELOPER_MODE=ON .. &&
|
||||
cmake --build . &&
|
||||
ctest . -E avoid_
|
||||
+1
-1
@@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.14)
|
||||
project(
|
||||
simdjson
|
||||
# The version number is modified by tools/release.py
|
||||
VERSION 3.1.5
|
||||
VERSION 3.1.6
|
||||
DESCRIPTION "Parsing gigabytes of JSON per second"
|
||||
HOMEPAGE_URL "https://simdjson.org/"
|
||||
LANGUAGES CXX C
|
||||
|
||||
@@ -38,7 +38,7 @@ PROJECT_NAME = simdjson
|
||||
# could be handy for archiving the generated documentation or if some version
|
||||
# control system is used.
|
||||
|
||||
PROJECT_NUMBER = "3.1.5"
|
||||
PROJECT_NUMBER = "3.1.6"
|
||||
|
||||
# Using the PROJECT_BRIEF tag one can provide an optional one line description
|
||||
# for a project that appears at the top of each page and should give viewer a
|
||||
|
||||
@@ -564,7 +564,7 @@ static void error_code_twitter_default_profile(State& state) noexcept {
|
||||
for (dom::element tweet : tweets) {
|
||||
dom::object user;
|
||||
if ((error = tweet["user"].get(user))) { return; }
|
||||
bool default_profile;
|
||||
bool default_profile{};
|
||||
if ((error = user["default_profile"].get(default_profile))) { return; }
|
||||
if (default_profile) {
|
||||
std::string_view screen_name;
|
||||
|
||||
@@ -161,6 +161,11 @@ else()
|
||||
)
|
||||
endif()
|
||||
|
||||
option(SIMDJSON_GLIBCXX_ASSERTIONS "Set _GLIBCXX_ASSERTIONS" OFF)
|
||||
if (SIMDJSON_GLIBCXX_ASSERTIONS)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_GLIBCXX_ASSERTIONS")
|
||||
endif()
|
||||
|
||||
#
|
||||
# Other optional flags
|
||||
#
|
||||
|
||||
+1
-1
@@ -1023,7 +1023,7 @@ bool parse() {
|
||||
cout << "Make/Model: " << make << "/" << model << endl;
|
||||
|
||||
// Casting a JSON element to an integer
|
||||
uint64_t year;
|
||||
uint64_t year{};
|
||||
error = car["year"].get(year);
|
||||
if(error) { std::cerr << error << std::endl; return false; }
|
||||
cout << "- This car is " << 2020 - year << " years old." << endl;
|
||||
|
||||
@@ -226,7 +226,7 @@ inline error_code parser::ensure_capacity(document& target_document, size_t desi
|
||||
}
|
||||
|
||||
simdjson_inline void parser::set_max_capacity(size_t max_capacity) noexcept {
|
||||
if(max_capacity < MINIMAL_DOCUMENT_CAPACITY) {
|
||||
if(max_capacity > MINIMAL_DOCUMENT_CAPACITY) {
|
||||
_max_capacity = max_capacity;
|
||||
} else {
|
||||
_max_capacity = MINIMAL_DOCUMENT_CAPACITY;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#define SIMDJSON_SIMDJSON_VERSION_H
|
||||
|
||||
/** The version of simdjson being used (major.minor.revision) */
|
||||
#define SIMDJSON_VERSION "3.1.5"
|
||||
#define SIMDJSON_VERSION "3.1.6"
|
||||
|
||||
namespace simdjson {
|
||||
enum {
|
||||
@@ -19,7 +19,7 @@ enum {
|
||||
/**
|
||||
* The revision (major.minor.REVISION) of simdjson being used.
|
||||
*/
|
||||
SIMDJSON_VERSION_REVISION = 5
|
||||
SIMDJSON_VERSION_REVISION = 6
|
||||
};
|
||||
} // namespace simdjson
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* auto-generated on 2023-03-09 11:14:42 -0500. Do not edit! */
|
||||
/* auto-generated on 2023-03-13 21:26:32 -0400. Do not edit! */
|
||||
/* begin file src/simdjson.cpp */
|
||||
#include "simdjson.h"
|
||||
|
||||
|
||||
+37
-4
@@ -1,4 +1,4 @@
|
||||
/* auto-generated on 2023-03-09 11:14:42 -0500. Do not edit! */
|
||||
/* auto-generated on 2023-03-13 21:26:32 -0400. Do not edit! */
|
||||
/* begin file include/simdjson.h */
|
||||
#ifndef SIMDJSON_H
|
||||
#define SIMDJSON_H
|
||||
@@ -43,7 +43,7 @@
|
||||
#define SIMDJSON_SIMDJSON_VERSION_H
|
||||
|
||||
/** The version of simdjson being used (major.minor.revision) */
|
||||
#define SIMDJSON_VERSION "3.1.5"
|
||||
#define SIMDJSON_VERSION "3.1.6"
|
||||
|
||||
namespace simdjson {
|
||||
enum {
|
||||
@@ -58,7 +58,7 @@ enum {
|
||||
/**
|
||||
* The revision (major.minor.REVISION) of simdjson being used.
|
||||
*/
|
||||
SIMDJSON_VERSION_REVISION = 5
|
||||
SIMDJSON_VERSION_REVISION = 6
|
||||
};
|
||||
} // namespace simdjson
|
||||
|
||||
@@ -265,6 +265,19 @@ use a 64-bit target such as x64, 64-bit ARM or 64-bit PPC.")
|
||||
#define SIMDJSON_NO_SANITIZE_UNDEFINED
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(__clang__) || defined(__GNUC__)
|
||||
#if defined(__has_feature)
|
||||
# if __has_feature(memory_sanitizer)
|
||||
#define SIMDJSON_NO_SANITIZE_MEMORY __attribute__((no_sanitize("memory")))
|
||||
# endif // if __has_feature(memory_sanitizer)
|
||||
#endif // defined(__has_feature)
|
||||
#endif
|
||||
// make sure it is defined as 'nothing' if it is unapplicable.
|
||||
#ifndef SIMDJSON_NO_SANITIZE_MEMORY
|
||||
#define SIMDJSON_NO_SANITIZE_MEMORY
|
||||
#endif
|
||||
|
||||
#if SIMDJSON_VISUAL_STUDIO
|
||||
// This is one case where we do not distinguish between
|
||||
// regular visual studio and clang under visual studio.
|
||||
@@ -8896,7 +8909,7 @@ inline error_code parser::ensure_capacity(document& target_document, size_t desi
|
||||
}
|
||||
|
||||
simdjson_inline void parser::set_max_capacity(size_t max_capacity) noexcept {
|
||||
if(max_capacity < MINIMAL_DOCUMENT_CAPACITY) {
|
||||
if(max_capacity > MINIMAL_DOCUMENT_CAPACITY) {
|
||||
_max_capacity = max_capacity;
|
||||
} else {
|
||||
_max_capacity = MINIMAL_DOCUMENT_CAPACITY;
|
||||
@@ -9845,6 +9858,10 @@ namespace {
|
||||
// but the algorithms do not end up using the returned value.
|
||||
// Sadly, sanitizers are not smart enough to figure it out.
|
||||
SIMDJSON_NO_SANITIZE_UNDEFINED
|
||||
// This function can be used safely even if not all bytes have been
|
||||
// initialized.
|
||||
// See issue https://github.com/simdjson/simdjson/issues/1965
|
||||
SIMDJSON_NO_SANITIZE_MEMORY
|
||||
simdjson_inline int trailing_zeroes(uint64_t input_num) {
|
||||
#ifdef SIMDJSON_REGULAR_VISUAL_STUDIO
|
||||
unsigned long ret;
|
||||
@@ -13956,6 +13973,10 @@ namespace {
|
||||
// but the algorithms do not end up using the returned value.
|
||||
// Sadly, sanitizers are not smart enough to figure it out.
|
||||
SIMDJSON_NO_SANITIZE_UNDEFINED
|
||||
// This function can be used safely even if not all bytes have been
|
||||
// initialized.
|
||||
// See issue https://github.com/simdjson/simdjson/issues/1965
|
||||
SIMDJSON_NO_SANITIZE_MEMORY
|
||||
simdjson_inline int trailing_zeroes(uint64_t input_num) {
|
||||
#if SIMDJSON_REGULAR_VISUAL_STUDIO
|
||||
return (int)_tzcnt_u64(input_num);
|
||||
@@ -16146,6 +16167,10 @@ namespace {
|
||||
// but the algorithms do not end up using the returned value.
|
||||
// Sadly, sanitizers are not smart enough to figure it out.
|
||||
SIMDJSON_NO_SANITIZE_UNDEFINED
|
||||
// This function can be used safely even if not all bytes have been
|
||||
// initialized.
|
||||
// See issue https://github.com/simdjson/simdjson/issues/1965
|
||||
SIMDJSON_NO_SANITIZE_MEMORY
|
||||
simdjson_inline int trailing_zeroes(uint64_t input_num) {
|
||||
#if SIMDJSON_REGULAR_VISUAL_STUDIO
|
||||
return (int)_tzcnt_u64(input_num);
|
||||
@@ -18292,6 +18317,10 @@ namespace {
|
||||
// but the algorithms do not end up using the returned value.
|
||||
// Sadly, sanitizers are not smart enough to figure it out.
|
||||
SIMDJSON_NO_SANITIZE_UNDEFINED
|
||||
// This function can be used safely even if not all bytes have been
|
||||
// initialized.
|
||||
// See issue https://github.com/simdjson/simdjson/issues/1965
|
||||
SIMDJSON_NO_SANITIZE_MEMORY
|
||||
simdjson_inline int trailing_zeroes(uint64_t input_num) {
|
||||
#if SIMDJSON_REGULAR_VISUAL_STUDIO
|
||||
unsigned long ret;
|
||||
@@ -20609,6 +20638,10 @@ namespace {
|
||||
// but the algorithms do not end up using the returned value.
|
||||
// Sadly, sanitizers are not smart enough to figure it out.
|
||||
SIMDJSON_NO_SANITIZE_UNDEFINED
|
||||
// This function can be used safely even if not all bytes have been
|
||||
// initialized.
|
||||
// See issue https://github.com/simdjson/simdjson/issues/1965
|
||||
SIMDJSON_NO_SANITIZE_MEMORY
|
||||
simdjson_inline int trailing_zeroes(uint64_t input_num) {
|
||||
#if SIMDJSON_REGULAR_VISUAL_STUDIO
|
||||
unsigned long ret;
|
||||
|
||||
+12
-12
@@ -59,28 +59,28 @@ private:
|
||||
|
||||
template<typename T>
|
||||
bool cast_tester<T>::test_get(element element, T expected) {
|
||||
T actual;
|
||||
T actual{};
|
||||
ASSERT_SUCCESS(element.get(actual));
|
||||
return assert_equal(actual, expected);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool cast_tester<T>::test_get(simdjson_result<element> element, T expected) {
|
||||
T actual;
|
||||
T actual{};
|
||||
ASSERT_SUCCESS(element.get(actual));
|
||||
return assert_equal(actual, expected);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool cast_tester<T>::test_get_error(element element, error_code expected_error) {
|
||||
T actual;
|
||||
T actual{};
|
||||
ASSERT_EQUAL(element.get(actual), expected_error);
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool cast_tester<T>::test_get_error(simdjson_result<element> element, error_code expected_error) {
|
||||
T actual;
|
||||
T actual{};
|
||||
ASSERT_EQUAL(element.get(actual), expected_error);
|
||||
return true;
|
||||
}
|
||||
@@ -113,28 +113,28 @@ bool cast_tester<T>::test_get_t_error(simdjson_result<element> element, error_co
|
||||
|
||||
template<typename T>
|
||||
bool cast_tester<T>::test_named_get(element element, T expected) {
|
||||
T actual;
|
||||
T actual{};
|
||||
ASSERT_SUCCESS(named_get(element).get(actual));
|
||||
return assert_equal(actual, expected);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool cast_tester<T>::test_named_get(simdjson_result<element> element, T expected) {
|
||||
T actual;
|
||||
T actual{};
|
||||
ASSERT_SUCCESS(named_get(element).get(actual));
|
||||
return assert_equal(actual, expected);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool cast_tester<T>::test_named_get_error(element element, error_code expected_error) {
|
||||
T actual;
|
||||
T actual{};
|
||||
ASSERT_EQUAL(named_get(element).get(actual), expected_error);
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool cast_tester<T>::test_named_get_error(simdjson_result<element> element, error_code expected_error) {
|
||||
T actual;
|
||||
T actual{};
|
||||
ASSERT_EQUAL(named_get(element).get(actual), expected_error);
|
||||
return true;
|
||||
}
|
||||
@@ -143,7 +143,7 @@ bool cast_tester<T>::test_named_get_error(simdjson_result<element> element, erro
|
||||
|
||||
template<typename T>
|
||||
bool cast_tester<T>::test_implicit_cast(element element, T expected) {
|
||||
T actual;
|
||||
T actual{};
|
||||
try {
|
||||
actual = element;
|
||||
} catch(simdjson_error &e) {
|
||||
@@ -155,7 +155,7 @@ bool cast_tester<T>::test_implicit_cast(element element, T expected) {
|
||||
|
||||
template<typename T>
|
||||
bool cast_tester<T>::test_implicit_cast(simdjson_result<element> element, T expected) {
|
||||
T actual;
|
||||
T actual{};
|
||||
try {
|
||||
actual = element;
|
||||
} catch(simdjson_error &e) {
|
||||
@@ -168,7 +168,7 @@ bool cast_tester<T>::test_implicit_cast(simdjson_result<element> element, T expe
|
||||
template<typename T>
|
||||
bool cast_tester<T>::test_implicit_cast_error(element element, error_code expected_error) {
|
||||
try {
|
||||
simdjson_unused T actual;
|
||||
simdjson_unused T actual{};
|
||||
actual = element;
|
||||
return false;
|
||||
} catch(simdjson_error &e) {
|
||||
@@ -180,7 +180,7 @@ bool cast_tester<T>::test_implicit_cast_error(element element, error_code expect
|
||||
template<typename T>
|
||||
bool cast_tester<T>::test_implicit_cast_error(simdjson_result<element> element, error_code expected_error) {
|
||||
try {
|
||||
simdjson_unused T actual;
|
||||
simdjson_unused T actual{};
|
||||
actual = element;
|
||||
return false;
|
||||
} catch(simdjson_error &e) {
|
||||
|
||||
@@ -74,7 +74,7 @@ namespace number_tests {
|
||||
for (int m = 10; m < 20; m++) {
|
||||
for (int i = -1024; i < 1024; i++) {
|
||||
auto str = std::to_string(i);
|
||||
int64_t actual;
|
||||
int64_t actual{};
|
||||
ASSERT_SUCCESS(parser.parse(str).get(actual));
|
||||
if (actual != i) {
|
||||
std::cerr << "JSON '" << str << "' parsed to " << actual << " instead of " << i << std::endl;
|
||||
|
||||
@@ -41,7 +41,7 @@ void basics_error_2() {
|
||||
cout << "Make/Model: " << make << "/" << model << endl;
|
||||
|
||||
// Casting a JSON element to an integer
|
||||
uint64_t year;
|
||||
uint64_t year{};
|
||||
if ((error = car["year"].get(year))) { cerr << error << endl; exit(1); }
|
||||
cout << "- This car is " << 2020 - year << "years old." << endl;
|
||||
|
||||
@@ -132,7 +132,7 @@ void basics_error_2_cpp17() {
|
||||
cout << "Make/Model: " << make << "/" << model << endl;
|
||||
|
||||
// Casting a JSON element to an integer
|
||||
uint64_t year;
|
||||
uint64_t year{};
|
||||
if ((error = car["year"].get(year))) { cerr << error << endl; exit(1); }
|
||||
cout << "- This car is " << 2020 - year << "years old." << endl;
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ namespace misc_tests {
|
||||
ASSERT_SUCCESS(val.get_object().get(obj));
|
||||
ondemand::array arr;
|
||||
ASSERT_SUCCESS(obj["a"].get_array().get(arr));
|
||||
size_t count{};
|
||||
size_t count{};
|
||||
ASSERT_SUCCESS(arr.count_elements().get(count));
|
||||
ASSERT_EQUAL(3,count);
|
||||
TEST_SUCCEED();
|
||||
|
||||
@@ -232,7 +232,7 @@ namespace number_tests {
|
||||
for(simdjson_result<ondemand::value> valr : arr) {
|
||||
ondemand::value val;
|
||||
ASSERT_SUCCESS(valr.get(val));
|
||||
ondemand::number_type nt;
|
||||
ondemand::number_type nt{};
|
||||
ASSERT_SUCCESS(val.get_number_type().get(nt));
|
||||
ASSERT_EQUAL(expectedtypes[counter], nt);
|
||||
ondemand::number num;
|
||||
@@ -339,7 +339,7 @@ namespace number_tests {
|
||||
ondemand::document doc;
|
||||
padded_string docdata;
|
||||
ondemand::number number;
|
||||
ondemand::number_type nt;
|
||||
ondemand::number_type nt{};
|
||||
|
||||
bool intvalue{};
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace object_error_tests {
|
||||
bool assert_iterate_object(T &&object, const char **expected_key, V *expected, size_t N, simdjson::error_code *expected_error, size_t N2) {
|
||||
size_t count = 0;
|
||||
for (auto field : object) {
|
||||
V actual;
|
||||
V actual{};
|
||||
auto actual_error = field.value().get(actual);
|
||||
if (count >= N) {
|
||||
ASSERT((count - N) < N2, "Extra error reported");
|
||||
|
||||
@@ -909,7 +909,7 @@ namespace object_tests {
|
||||
ondemand::document doc;
|
||||
ASSERT_SUCCESS(parser.iterate(json).get(doc));
|
||||
ondemand::object obj;
|
||||
size_t count{};
|
||||
size_t count;
|
||||
ASSERT_SUCCESS(doc.get_object().get(obj));
|
||||
ASSERT_SUCCESS(obj.count_fields().get(count));
|
||||
ASSERT_EQUAL(count, 0);
|
||||
@@ -924,7 +924,7 @@ namespace object_tests {
|
||||
ASSERT_SUCCESS(parser.iterate(json).get(doc));
|
||||
ondemand::object obj;
|
||||
ASSERT_SUCCESS(doc.get_object().get(obj));
|
||||
size_t count{};
|
||||
size_t count;
|
||||
ASSERT_SUCCESS(obj.count_fields().get(count));
|
||||
ASSERT_EQUAL(count, 0);
|
||||
for (auto field : obj) {
|
||||
@@ -943,7 +943,7 @@ namespace object_tests {
|
||||
ondemand::parser parser;
|
||||
ondemand::document doc;
|
||||
ASSERT_SUCCESS(parser.iterate(json).get(doc));
|
||||
size_t count{};
|
||||
size_t count;
|
||||
ASSERT_SUCCESS(doc.count_fields().get(count));
|
||||
ondemand::object obj;
|
||||
ASSERT_SUCCESS(doc.get_object().get(obj));
|
||||
@@ -989,7 +989,7 @@ namespace object_tests {
|
||||
for (auto d : data) {
|
||||
simdjson::ondemand::object obj;
|
||||
ASSERT_SUCCESS(d.get_object().get(obj));
|
||||
size_t count{};
|
||||
size_t count;
|
||||
ASSERT_SUCCESS(obj.count_fields().get(count));
|
||||
ASSERT_EQUAL(count, 7);
|
||||
}
|
||||
@@ -1025,7 +1025,7 @@ namespace object_tests {
|
||||
simdjson::ondemand::array data;
|
||||
ASSERT_SUCCESS(doc["result"]["data"].get_array().get(data));
|
||||
for (auto d : data) {
|
||||
size_t count{};
|
||||
size_t count;
|
||||
ASSERT_SUCCESS(d.count_fields().get(count));
|
||||
ASSERT_EQUAL(count, 7);
|
||||
}
|
||||
@@ -1039,7 +1039,7 @@ namespace object_tests {
|
||||
ondemand::document doc;
|
||||
ASSERT_SUCCESS(parser.iterate(json).get(doc));
|
||||
ondemand::object obj;
|
||||
size_t count{};
|
||||
size_t count;
|
||||
ASSERT_SUCCESS(doc.get_object().get(obj));
|
||||
ASSERT_SUCCESS(obj.count_fields().get(count));
|
||||
ASSERT_EQUAL(count, 5);
|
||||
@@ -1101,7 +1101,7 @@ namespace object_tests {
|
||||
TEST_START();
|
||||
auto empty = R"( {} )"_padded;
|
||||
SUBTEST("ondemand::empty_doc_object", test_ondemand_doc(empty, [&](auto doc_result) {
|
||||
size_t count{};
|
||||
size_t count;
|
||||
ASSERT_RESULT( doc_result.type(), json_type::object );
|
||||
ASSERT_SUCCESS( doc_result.count_fields().get(count) );
|
||||
ASSERT_EQUAL( count, 0 );
|
||||
@@ -1109,7 +1109,7 @@ namespace object_tests {
|
||||
}));
|
||||
auto basic = R"( {"a":-1.234, "b":false, "c":null, "d":[1000.1,-2000.2,3000.3], "e":{"a":true, "b":false}} )"_padded;
|
||||
SUBTEST("ondemand::basic_doc_object", test_ondemand_doc(basic, [&](auto doc_result) {
|
||||
size_t count{};
|
||||
size_t count;
|
||||
ASSERT_RESULT( doc_result.type(), json_type::object );
|
||||
ASSERT_SUCCESS( doc_result.count_fields().get(count) );
|
||||
ASSERT_EQUAL( count, 5 );
|
||||
|
||||
@@ -320,7 +320,7 @@ bool json_object_count() {
|
||||
ondemand::parser parser;
|
||||
ondemand::document doc;
|
||||
ASSERT_SUCCESS(parser.iterate(json).get(doc));
|
||||
size_t count{};
|
||||
size_t count;
|
||||
ASSERT_SUCCESS(doc.count_fields().get(count));
|
||||
ASSERT_EQUAL(count,1);
|
||||
ondemand::object object;
|
||||
@@ -576,7 +576,7 @@ bool using_the_parsed_json_no_exceptions() {
|
||||
cout << "Make/Model: " << make << "/" << model << endl;
|
||||
|
||||
// Casting a JSON element to an integer
|
||||
uint64_t year;
|
||||
uint64_t year{};
|
||||
error = car["year"].get(year);
|
||||
if(error) { std::cerr << error << std::endl; return false; }
|
||||
cout << "- This car is " << 2020 - year << " years old." << endl;
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace scalar_tests {
|
||||
bool test_scalar_value(const padded_string &json, const T &expected, bool test_twice=true) {
|
||||
std::cout << "- JSON: " << json << endl;
|
||||
SUBTEST( "simdjson_result<document>", test_ondemand_doc(json, [&](auto doc_result) {
|
||||
T actual;
|
||||
T actual{};
|
||||
ASSERT_RESULT( doc_result.type(), expected_json_type<T>() );
|
||||
ASSERT_SUCCESS( doc_result.get(actual) );
|
||||
ASSERT_EQUAL( actual, expected );
|
||||
@@ -33,7 +33,7 @@ namespace scalar_tests {
|
||||
SUBTEST( "document", test_ondemand_doc(json, [&](auto doc_result) {
|
||||
ondemand::document doc;
|
||||
ASSERT_SUCCESS( std::move(doc_result).get(doc) );
|
||||
T actual;
|
||||
T actual{};
|
||||
ASSERT_RESULT( doc.type(), expected_json_type<T>() );
|
||||
ASSERT_SUCCESS( doc.get(actual) );
|
||||
ASSERT_EQUAL( actual, expected );
|
||||
@@ -50,7 +50,7 @@ namespace scalar_tests {
|
||||
padded_string whitespace_json = std::string(json) + " ";
|
||||
std::cout << "- JSON: " << whitespace_json << endl;
|
||||
SUBTEST( "simdjson_result<document>", test_ondemand_doc(whitespace_json, [&](auto doc_result) {
|
||||
T actual;
|
||||
T actual{};
|
||||
ASSERT_RESULT( doc_result.type(), expected_json_type<T>() );
|
||||
ASSERT_SUCCESS( doc_result.get(actual) );
|
||||
ASSERT_EQUAL( actual, expected );
|
||||
@@ -65,7 +65,7 @@ namespace scalar_tests {
|
||||
SUBTEST( "document", test_ondemand_doc(whitespace_json, [&](auto doc_result) {
|
||||
ondemand::document doc;
|
||||
ASSERT_SUCCESS( std::move(doc_result).get(doc) );
|
||||
T actual;
|
||||
T actual{};
|
||||
ASSERT_RESULT( doc.type(), expected_json_type<T>() );
|
||||
ASSERT_SUCCESS( doc.get(actual) );
|
||||
ASSERT_EQUAL( actual, expected );
|
||||
@@ -85,7 +85,7 @@ namespace scalar_tests {
|
||||
SUBTEST( "simdjson_result<value>", test_ondemand_doc(array_json, [&](auto doc_result) {
|
||||
int count = 0;
|
||||
for (simdjson_result<ondemand::value> val_result : doc_result) {
|
||||
T actual;
|
||||
T actual{};
|
||||
ASSERT_RESULT( val_result.type(), expected_json_type<T>() );
|
||||
ASSERT_SUCCESS( val_result.get(actual) );
|
||||
ASSERT_EQUAL(actual, expected);
|
||||
@@ -105,7 +105,7 @@ namespace scalar_tests {
|
||||
for (simdjson_result<ondemand::value> val_result : doc_result) {
|
||||
ondemand::value val;
|
||||
ASSERT_SUCCESS( val_result.get(val) );
|
||||
T actual;
|
||||
T actual{};
|
||||
ASSERT_RESULT( val.type(), expected_json_type<T>() );
|
||||
ASSERT_SUCCESS( val.get(actual) );
|
||||
ASSERT_EQUAL(actual, expected);
|
||||
@@ -129,7 +129,7 @@ namespace scalar_tests {
|
||||
SUBTEST( "simdjson_result<value>", test_ondemand_doc(whitespace_array_json, [&](auto doc_result) {
|
||||
int count = 0;
|
||||
for (simdjson_result<ondemand::value> val_result : doc_result) {
|
||||
T actual;
|
||||
T actual{};
|
||||
ASSERT_RESULT( val_result.type(), expected_json_type<T>() );
|
||||
ASSERT_SUCCESS( val_result.get(actual) );
|
||||
ASSERT_EQUAL(actual, expected);
|
||||
@@ -150,7 +150,7 @@ namespace scalar_tests {
|
||||
for (simdjson_result<ondemand::value> val_result : doc_result) {
|
||||
ondemand::value val;
|
||||
ASSERT_SUCCESS( val_result.get(val) );
|
||||
T actual;
|
||||
T actual{};
|
||||
ASSERT_RESULT( val.type(), expected_json_type<T>() );
|
||||
ASSERT_SUCCESS( val.get(actual) );
|
||||
ASSERT_EQUAL(actual, expected);
|
||||
|
||||
@@ -56,7 +56,7 @@ namespace twitter_tests {
|
||||
std::string_view screen_name;
|
||||
ASSERT_SUCCESS( user["screen_name"].get(screen_name) );
|
||||
|
||||
bool default_profile;
|
||||
bool default_profile{};
|
||||
ASSERT_SUCCESS( user["default_profile"].get(default_profile) );
|
||||
if (default_profile) {
|
||||
default_users.insert(screen_name);
|
||||
@@ -79,7 +79,7 @@ namespace twitter_tests {
|
||||
auto media = tweet["entities"]["media"];
|
||||
if (!media.error()) {
|
||||
for (auto image : media) {
|
||||
uint64_t id_val{};
|
||||
uint64_t id_val;
|
||||
std::string_view id_string;
|
||||
ASSERT_SUCCESS( image["id"].get(id_val) );
|
||||
ASSERT_SUCCESS( image["id_str"].get(id_string) );
|
||||
@@ -91,8 +91,7 @@ namespace twitter_tests {
|
||||
ASSERT_SUCCESS( size.unescaped_key().get(size_key) );
|
||||
std::cout << "Type of image size = " << size_key << std::endl;
|
||||
|
||||
uint64_t width{};
|
||||
uint64_t height{};
|
||||
uint64_t width, height;
|
||||
ASSERT_SUCCESS( size.value()["w"].get(width) );
|
||||
ASSERT_SUCCESS( size.value()["h"].get(height) );
|
||||
image_sizes.insert(make_pair(width, height));
|
||||
|
||||
Reference in New Issue
Block a user