From c5d19a4dbd1487994a23fa1a76e6cf311037c542 Mon Sep 17 00:00:00 2001 From: Benoit Blanchon Date: Fri, 6 May 2016 08:44:31 +0200 Subject: [PATCH] Changed `::String` to `ArduinoJson::String` (issue #275) --- CHANGELOG.md | 6 ++++++ include/ArduinoJson/Configuration.hpp | 10 ++++++++++ include/ArduinoJson/Internals/DummyPrint.hpp | 2 +- .../ArduinoJson/Internals/DynamicStringBuilder.hpp | 4 ++-- include/ArduinoJson/Internals/Encoding.hpp | 2 +- include/ArduinoJson/Internals/IndentedPrint.hpp | 2 +- include/ArduinoJson/Internals/JsonWriter.hpp | 4 ++-- .../ArduinoJson/Internals/StaticStringBuilder.hpp | 2 +- .../ArduinoJson/Internals/StreamPrintAdapter.hpp | 2 +- include/ArduinoJson/JsonBuffer.hpp | 2 +- include/ArduinoJson/JsonObject.hpp | 2 +- include/ArduinoJson/JsonObjectKey.hpp | 2 +- include/ArduinoJson/{Arduino => }/Print.hpp | 2 ++ include/ArduinoJson/{Arduino => }/String.hpp | 13 +++++++++---- test/StringBuilderTests.cpp | 2 +- 15 files changed, 40 insertions(+), 17 deletions(-) rename include/ArduinoJson/{Arduino => }/Print.hpp (95%) rename include/ArduinoJson/{Arduino => }/String.hpp (74%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 76a46589f..390740491 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ ArduinoJson: change log ======================= +HEAD +---- + +* Changed `::String` to `ArduinoJson::String` (issue #275) +* Changed `::Print` to `ArduinoJson::Print` too + v5.3.0 ------ diff --git a/include/ArduinoJson/Configuration.hpp b/include/ArduinoJson/Configuration.hpp index 8956827da..c0b88ece7 100644 --- a/include/ArduinoJson/Configuration.hpp +++ b/include/ArduinoJson/Configuration.hpp @@ -22,6 +22,11 @@ #define ARDUINOJSON_USE_INT64 0 #endif +// arduino has its own implementation of String to replace std::string +#ifndef ARDUINOJSON_USE_ARDUINO_STRING +#define ARDUINOJSON_USE_ARDUINO_STRING 1 +#endif + // arduino doesn't support STL stream #ifndef ARDUINOJSON_ENABLE_STD_STREAM #define ARDUINOJSON_ENABLE_STD_STREAM 0 @@ -62,6 +67,11 @@ #endif #endif +// on a computer, we can use std::string +#ifndef ARDUINOJSON_USE_ARDUINO_STRING +#define ARDUINOJSON_USE_ARDUINO_STRING 0 +#endif + // on a computer, we can assume that the STL is there #ifndef ARDUINOJSON_ENABLE_STD_STREAM #define ARDUINOJSON_ENABLE_STD_STREAM 1 diff --git a/include/ArduinoJson/Internals/DummyPrint.hpp b/include/ArduinoJson/Internals/DummyPrint.hpp index c6779dd26..4e9efcaae 100644 --- a/include/ArduinoJson/Internals/DummyPrint.hpp +++ b/include/ArduinoJson/Internals/DummyPrint.hpp @@ -7,7 +7,7 @@ #pragma once -#include "../Arduino/Print.hpp" +#include "../Print.hpp" namespace ArduinoJson { namespace Internals { diff --git a/include/ArduinoJson/Internals/DynamicStringBuilder.hpp b/include/ArduinoJson/Internals/DynamicStringBuilder.hpp index 0dc64a294..035646ff0 100644 --- a/include/ArduinoJson/Internals/DynamicStringBuilder.hpp +++ b/include/ArduinoJson/Internals/DynamicStringBuilder.hpp @@ -7,8 +7,8 @@ #pragma once -#include "../Arduino/Print.hpp" -#include "../Arduino/String.hpp" +#include "../Print.hpp" +#include "../String.hpp" namespace ArduinoJson { namespace Internals { diff --git a/include/ArduinoJson/Internals/Encoding.hpp b/include/ArduinoJson/Internals/Encoding.hpp index cd4288cf2..571f60875 100644 --- a/include/ArduinoJson/Internals/Encoding.hpp +++ b/include/ArduinoJson/Internals/Encoding.hpp @@ -7,7 +7,7 @@ #pragma once -#include "../Arduino/Print.hpp" +#include "../Print.hpp" namespace ArduinoJson { namespace Internals { diff --git a/include/ArduinoJson/Internals/IndentedPrint.hpp b/include/ArduinoJson/Internals/IndentedPrint.hpp index ebffc700f..6bc0009db 100644 --- a/include/ArduinoJson/Internals/IndentedPrint.hpp +++ b/include/ArduinoJson/Internals/IndentedPrint.hpp @@ -7,7 +7,7 @@ #pragma once -#include "../Arduino/Print.hpp" +#include "../Print.hpp" namespace ArduinoJson { namespace Internals { diff --git a/include/ArduinoJson/Internals/JsonWriter.hpp b/include/ArduinoJson/Internals/JsonWriter.hpp index fd4b55c3f..a73621bed 100644 --- a/include/ArduinoJson/Internals/JsonWriter.hpp +++ b/include/ArduinoJson/Internals/JsonWriter.hpp @@ -7,10 +7,10 @@ #pragma once -#include "../Arduino/Print.hpp" -#include "../Polyfills/isNaN.hpp" #include "../Polyfills/isInfinity.hpp" +#include "../Polyfills/isNaN.hpp" #include "../Polyfills/normalize.hpp" +#include "../Print.hpp" #include "Encoding.hpp" #include "ForceInline.hpp" #include "JsonFloat.hpp" diff --git a/include/ArduinoJson/Internals/StaticStringBuilder.hpp b/include/ArduinoJson/Internals/StaticStringBuilder.hpp index 037551ed3..a44800fc1 100644 --- a/include/ArduinoJson/Internals/StaticStringBuilder.hpp +++ b/include/ArduinoJson/Internals/StaticStringBuilder.hpp @@ -7,7 +7,7 @@ #pragma once -#include "../Arduino/Print.hpp" +#include "../Print.hpp" namespace ArduinoJson { namespace Internals { diff --git a/include/ArduinoJson/Internals/StreamPrintAdapter.hpp b/include/ArduinoJson/Internals/StreamPrintAdapter.hpp index 68e9fdfba..e954ea4a6 100644 --- a/include/ArduinoJson/Internals/StreamPrintAdapter.hpp +++ b/include/ArduinoJson/Internals/StreamPrintAdapter.hpp @@ -11,7 +11,7 @@ #if ARDUINOJSON_ENABLE_STD_STREAM -#include "../Arduino/Print.hpp" +#include "../Print.hpp" #include diff --git a/include/ArduinoJson/JsonBuffer.hpp b/include/ArduinoJson/JsonBuffer.hpp index 9cf2408a5..128a3511d 100644 --- a/include/ArduinoJson/JsonBuffer.hpp +++ b/include/ArduinoJson/JsonBuffer.hpp @@ -11,7 +11,7 @@ #include // for uint8_t #include -#include "Arduino/String.hpp" +#include "String.hpp" #include "JsonVariant.hpp" #if defined(__clang__) diff --git a/include/ArduinoJson/JsonObject.hpp b/include/ArduinoJson/JsonObject.hpp index d72f5f946..8a26a3a6d 100644 --- a/include/ArduinoJson/JsonObject.hpp +++ b/include/ArduinoJson/JsonObject.hpp @@ -7,7 +7,7 @@ #pragma once -#include "Arduino/String.hpp" +#include "String.hpp" #include "Internals/JsonBufferAllocated.hpp" #include "Internals/JsonPrintable.hpp" #include "Internals/List.hpp" diff --git a/include/ArduinoJson/JsonObjectKey.hpp b/include/ArduinoJson/JsonObjectKey.hpp index 22876aff2..982a989f9 100644 --- a/include/ArduinoJson/JsonObjectKey.hpp +++ b/include/ArduinoJson/JsonObjectKey.hpp @@ -7,7 +7,7 @@ #pragma once -#include "Arduino/String.hpp" +#include "String.hpp" namespace ArduinoJson { diff --git a/include/ArduinoJson/Arduino/Print.hpp b/include/ArduinoJson/Print.hpp similarity index 95% rename from include/ArduinoJson/Arduino/Print.hpp rename to include/ArduinoJson/Print.hpp index a68f8d5eb..4a880a55e 100644 --- a/include/ArduinoJson/Arduino/Print.hpp +++ b/include/ArduinoJson/Print.hpp @@ -12,6 +12,7 @@ #include #include +namespace ArduinoJson { // This class reproduces Arduino's Print class class Print { public: @@ -29,6 +30,7 @@ class Print { size_t println() { return write('\r') + write('\n'); } }; +} #else diff --git a/include/ArduinoJson/Arduino/String.hpp b/include/ArduinoJson/String.hpp similarity index 74% rename from include/ArduinoJson/Arduino/String.hpp rename to include/ArduinoJson/String.hpp index 9b9536e24..925800525 100644 --- a/include/ArduinoJson/Arduino/String.hpp +++ b/include/ArduinoJson/String.hpp @@ -7,13 +7,18 @@ #pragma once -#ifndef ARDUINO +#include "Configuration.hpp" -#include -typedef std::string String; +#if ARDUINOJSON_USE_ARDUINO_STRING + +#include #else -#include +#include + +namespace ArduinoJson { +typedef std::string String; +} #endif diff --git a/test/StringBuilderTests.cpp b/test/StringBuilderTests.cpp index 7eedd7693..c8aede9ae 100644 --- a/test/StringBuilderTests.cpp +++ b/test/StringBuilderTests.cpp @@ -5,8 +5,8 @@ // https://github.com/bblanchon/ArduinoJson // If you like this project, please add a star! +#include #include -#include using namespace ArduinoJson::Internals;