diff --git a/CHANGELOG.md b/CHANGELOG.md index 04604e1d..88ce9393 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ HEAD ---- * Fix error `'std::string' has not been declared` (issue #1967) +* Fix error `'std::string_view' has not been declared` (issue #1967) v6.21.3 (2023-07-23) ------- diff --git a/extras/tests/Cpp17/string_view.cpp b/extras/tests/Cpp17/string_view.cpp index 6a51ce2d..7ef65626 100644 --- a/extras/tests/Cpp17/string_view.cpp +++ b/extras/tests/Cpp17/string_view.cpp @@ -1,8 +1,16 @@ +// ArduinoJson - https://arduinojson.org +// Copyright © 2014-2023, Benoit BLANCHON +// MIT License + +// we expect ArduinoJson.h to include +// but we don't want it to included accidentally +#undef ARDUINO +#define ARDUINOJSON_ENABLE_STD_STREAM 0 +#define ARDUINOJSON_ENABLE_STD_STRING 0 + #include #include -#include - #if !ARDUINOJSON_ENABLE_STRING_VIEW # error ARDUINOJSON_ENABLE_STRING_VIEW must be set to 1 #endif @@ -19,7 +27,7 @@ TEST_CASE("string_view") { SECTION("JsonDocument::set()") { doc.set(std::string_view("123", 2)); - REQUIRE(doc.as() == "12"); + REQUIRE(doc.as() == "12"); } SECTION("JsonDocument::operator[]() const") { diff --git a/src/ArduinoJson/Variant/ConverterImpl.hpp b/src/ArduinoJson/Variant/ConverterImpl.hpp index 5318242b..0708f52f 100644 --- a/src/ArduinoJson/Variant/ConverterImpl.hpp +++ b/src/ArduinoJson/Variant/ConverterImpl.hpp @@ -12,6 +12,10 @@ # include #endif +#if ARDUINOJSON_ENABLE_STRING_VIEW +# include +#endif + ARDUINOJSON_BEGIN_PUBLIC_NAMESPACE template