diff --git a/.gitignore b/.gitignore index 24f31d8..319a48e 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ /*.a /*.ok /*_test +/build/* +/cmake-build-* \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..ee14399 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,70 @@ +cmake_minimum_required(VERSION 3.5) +project(json_cpp) + +# options + +set(JART_JSON_CPP_LIBRARY_NAME ${CMAKE_PROJECT_NAME} CACHE STRING "CMake target name and library name of json.cpp, default to 'json_cpp' (project name)") +option(JART_JSON_CPP_ENABLE_TEST "enable json.cpp test" ON) +option(JART_JSON_CPP_ENABLE_TEST_JSON_TEST_SUITE "enable json.cpp json test suite" ON) + +# library: double conversion + +set(DOUBLE_CONVERSION_LIBRARY_NAME "${JART_JSON_CPP_LIBRARY_NAME}_double_conversion") +add_library(${DOUBLE_CONVERSION_LIBRARY_NAME} STATIC) +target_compile_features(${DOUBLE_CONVERSION_LIBRARY_NAME} PRIVATE cxx_std_17) +target_include_directories(${DOUBLE_CONVERSION_LIBRARY_NAME} PUBLIC double-conversion) +target_sources(${DOUBLE_CONVERSION_LIBRARY_NAME} PRIVATE + double-conversion/bignum-dtoa.cc + double-conversion/bignum-dtoa.h + double-conversion/bignum.cc + double-conversion/bignum.h + double-conversion/cached-powers.cc + double-conversion/cached-powers.h + double-conversion/diy-fp.h + double-conversion/double-conversion.h + double-conversion/double-to-string.cc + double-conversion/double-to-string.h + double-conversion/fast-dtoa.cc + double-conversion/fast-dtoa.h + double-conversion/fixed-dtoa.cc + double-conversion/fixed-dtoa.h + double-conversion/ieee.h + double-conversion/string-to-double.cc + double-conversion/string-to-double.h + double-conversion/strtod.cc + double-conversion/strtod.h + double-conversion/utils.h +) + +# library: json.cpp + +set(LIBRARY_NAME ${JART_JSON_CPP_LIBRARY_NAME}) +add_library(${LIBRARY_NAME} STATIC) +target_compile_features(${LIBRARY_NAME} PRIVATE cxx_std_17) +target_include_directories(${LIBRARY_NAME} PUBLIC .) +target_sources(${LIBRARY_NAME} PRIVATE + jtckdint.h + json.h + json.cpp +) +target_link_libraries(${LIBRARY_NAME} INTERFACE ${DOUBLE_CONVERSION_LIBRARY_NAME}) + +# test: benchmark + +if (JART_JSON_CPP_ENABLE_TEST) + set(TEST_NAME "${JART_JSON_CPP_LIBRARY_NAME}_test") + add_executable(${TEST_NAME}) + target_compile_features(${TEST_NAME} PRIVATE cxx_std_17) + target_sources(${TEST_NAME} PRIVATE json_test.cpp) + target_link_libraries(${TEST_NAME} PRIVATE ${LIBRARY_NAME}) +endif () + +# test: json test suite + +if (JART_JSON_CPP_ENABLE_TEST_JSON_TEST_SUITE) + set(TEST_JSON_TEST_SUITE_NAME "${JART_JSON_CPP_LIBRARY_NAME}_test_json_test_suite") + add_executable(${TEST_JSON_TEST_SUITE_NAME}) + target_compile_features(${TEST_JSON_TEST_SUITE_NAME} PRIVATE cxx_std_17) + target_sources(${TEST_JSON_TEST_SUITE_NAME} PRIVATE jsontestsuite_test.cpp) + target_link_libraries(${TEST_JSON_TEST_SUITE_NAME} PRIVATE ${LIBRARY_NAME}) +endif () diff --git a/json.cpp b/json.cpp index 420b2c9..56f86b7 100644 --- a/json.cpp +++ b/json.cpp @@ -881,7 +881,15 @@ Json::parse(Json& json, const char*& p, const char* e, int context, int depth) json.setLong(0); return success; - case '1' ... '9': // integer + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': // integer if (context & (COLON | COMMA | KEY)) goto OnColonCommaKey; for (x = (c - '0') * d; p < e; ++p) { diff --git a/json_test.cpp b/json_test.cpp index e222ada..f56c65b 100644 --- a/json_test.cpp +++ b/json_test.cpp @@ -101,7 +101,7 @@ struct timespec now(void) { struct timespec ts; - clock_gettime(CLOCK_REALTIME, &ts); + timespec_get(&ts, TIME_UTC); return ts; } diff --git a/jsontestsuite_test.cpp b/jsontestsuite_test.cpp index b5fe16e..719eeed 100644 --- a/jsontestsuite_test.cpp +++ b/jsontestsuite_test.cpp @@ -19,7 +19,6 @@ #include #include -#include #define HI_RESET "\033[0m" // green #define HI_GOOD "\033[32m" // green