Эх сурвалжийг харах

Fix 'std::string_view' has not been declared (issue #1967)

Ported from 49e2a8d421d7f442ac397d42caa3f60b2c00db54
Benoit Blanchon 2 жил өмнө
parent
commit
92c9faf69f

+ 11 - 3
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 <string_view>
+// but we don't want it to included accidentally
+#undef ARDUINO
+#define ARDUINOJSON_ENABLE_STD_STREAM 0
+#define ARDUINOJSON_ENABLE_STD_STRING 0
+
 #include <ArduinoJson.h>
 #include <catch.hpp>
 
-#include <string_view>
-
 #include "Allocators.hpp"
 
 #if !ARDUINOJSON_ENABLE_STRING_VIEW
@@ -24,7 +32,7 @@ TEST_CASE("string_view") {
 
   SECTION("JsonDocument::set()") {
     doc.set(std::string_view("123", 2));
-    REQUIRE(doc.as<std::string>() == "12");
+    REQUIRE(doc.as<std::string_view>() == "12");
   }
 
   SECTION("JsonDocument::operator[]() const") {

+ 4 - 0
src/ArduinoJson/Variant/ConverterImpl.hpp

@@ -13,6 +13,10 @@
 #  include <string>
 #endif
 
+#if ARDUINOJSON_ENABLE_STRING_VIEW
+#  include <string_view>
+#endif
+
 ARDUINOJSON_BEGIN_PUBLIC_NAMESPACE
 
 template <typename T, typename Enable>