From 0d78b117ffd546201bdc6554987164c863131e1f Mon Sep 17 00:00:00 2001 From: cbookshu Date: Mon, 9 Dec 2024 11:12:45 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=A7=A3=E6=9E=90optiona?= =?UTF-8?q?l=20=E9=81=87=E5=88=B0=20'n'=20=E5=BC=80=E5=A4=B4?= =?UTF-8?q?=E6=97=B6=E5=BC=82=E5=B8=B8=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- iguana/json_reader.hpp | 4 ++-- test/test_json_files.cpp | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/iguana/json_reader.hpp b/iguana/json_reader.hpp index 768610dc..8e26b42d 100644 --- a/iguana/json_reader.hpp +++ b/iguana/json_reader.hpp @@ -450,8 +450,6 @@ IGUANA_INLINE void from_json_impl(U &value, It &&it, It &&end) { template , int> = 0> IGUANA_INLINE void from_json_impl(U &value, It &&it, It &&end) { skip_ws(it, end); - if (it < end && *it == '"') - IGUANA_LIKELY { ++it; } using T = std::remove_reference_t; if (it == end) IGUANA_UNLIKELY { throw std::runtime_error("Unexexpected eof"); } @@ -469,6 +467,8 @@ IGUANA_INLINE void from_json_impl(U &value, It &&it, It &&end) { using value_type = typename T::value_type; value_type t; if constexpr (string_v || string_view_v) { + if (it < end && *it == '"') + IGUANA_LIKELY { ++it; } from_json_impl(t, it, end); } else { diff --git a/test/test_json_files.cpp b/test/test_json_files.cpp index 035c5b48..8dbdcb45 100644 --- a/test/test_json_files.cpp +++ b/test/test_json_files.cpp @@ -314,6 +314,22 @@ TEST_CASE("test instruments.json") { } } +struct test_optstr_reader_null { + std::optional name; +}; +YLT_REFL(test_optstr_reader_null, name); +TEST_CASE("test_optstr_reader") { + + test_optstr_reader_null v; + v.name = "name"; // n开头的optional 字符串 + std::string json; + iguana::to_json(v, json); + + test_optstr_reader_null v1; + iguana::from_json(v1, json); + CHECK(v.name == v1.name); +} + // doctest comments // 'function' : must be 'attribute' - see issue #182 DOCTEST_MSVC_SUPPRESS_WARNING_WITH_PUSH(4007) int main(int argc, char **argv) { From 241560edf55dc2749652835631525dc5a468f1ba Mon Sep 17 00:00:00 2001 From: cbookshu Date: Mon, 9 Dec 2024 03:28:27 +0000 Subject: [PATCH 2/4] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=BC=96=E7=A0=81?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/test_json_files.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_json_files.cpp b/test/test_json_files.cpp index 8dbdcb45..5730f984 100644 --- a/test/test_json_files.cpp +++ b/test/test_json_files.cpp @@ -321,7 +321,7 @@ YLT_REFL(test_optstr_reader_null, name); TEST_CASE("test_optstr_reader") { test_optstr_reader_null v; - v.name = "name"; // n开头的optional 字符串 + v.name = "name"; // optional begin with 'n' std::string json; iguana::to_json(v, json); From 6a8d8053415f9c35dd9e4c8816c866776a7c7252 Mon Sep 17 00:00:00 2001 From: qicosmos <383121719@qq.com> Date: Mon, 9 Dec 2024 11:55:46 +0800 Subject: [PATCH 3/4] format --- test/test_json_files.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/test/test_json_files.cpp b/test/test_json_files.cpp index 5730f984..1a889449 100644 --- a/test/test_json_files.cpp +++ b/test/test_json_files.cpp @@ -315,19 +315,18 @@ TEST_CASE("test instruments.json") { } struct test_optstr_reader_null { - std::optional name; + std::optional name; }; YLT_REFL(test_optstr_reader_null, name); TEST_CASE("test_optstr_reader") { - - test_optstr_reader_null v; - v.name = "name"; // optional begin with 'n' - std::string json; - iguana::to_json(v, json); - - test_optstr_reader_null v1; - iguana::from_json(v1, json); - CHECK(v.name == v1.name); + test_optstr_reader_null v; + v.name = "name"; // optional begin with 'n' + std::string json; + iguana::to_json(v, json); + + test_optstr_reader_null v1; + iguana::from_json(v1, json); + CHECK(v.name == v1.name); } // doctest comments From 9d882b2a4efc190577f7865845c66bf096f1ae15 Mon Sep 17 00:00:00 2001 From: qicosmos <383121719@qq.com> Date: Mon, 9 Dec 2024 11:58:25 +0800 Subject: [PATCH 4/4] format --- test/test_json_files.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_json_files.cpp b/test/test_json_files.cpp index 1a889449..2d609cb9 100644 --- a/test/test_json_files.cpp +++ b/test/test_json_files.cpp @@ -320,7 +320,7 @@ struct test_optstr_reader_null { YLT_REFL(test_optstr_reader_null, name); TEST_CASE("test_optstr_reader") { test_optstr_reader_null v; - v.name = "name"; // optional begin with 'n' + v.name = "name"; // optional begin with 'n' std::string json; iguana::to_json(v, json);