summaryrefslogtreecommitdiff
path: root/include/lib/ArduinoJson/StringTraits/FlashString.hpp
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2018-09-17 10:02:07 +0200
committerDaniel Friesel <derf@finalrewind.org>2018-09-17 10:02:07 +0200
commit4f6253aa9fec99260b8bb7b9b2e9003f5259b600 (patch)
tree2d0a3fdd10e258ecce5fb220547b1c43b870d6d2 /include/lib/ArduinoJson/StringTraits/FlashString.hpp
parent30c4f72770568749b4230a6b598e3fb87a065e91 (diff)
Import arduinojson and ubjson. Only partially working at the moment
Diffstat (limited to 'include/lib/ArduinoJson/StringTraits/FlashString.hpp')
-rw-r--r--include/lib/ArduinoJson/StringTraits/FlashString.hpp61
1 files changed, 61 insertions, 0 deletions
diff --git a/include/lib/ArduinoJson/StringTraits/FlashString.hpp b/include/lib/ArduinoJson/StringTraits/FlashString.hpp
new file mode 100644
index 0000000..0701b9b
--- /dev/null
+++ b/include/lib/ArduinoJson/StringTraits/FlashString.hpp
@@ -0,0 +1,61 @@
+// ArduinoJson - arduinojson.org
+// Copyright Benoit Blanchon 2014-2018
+// MIT License
+
+#pragma once
+
+#if ARDUINOJSON_ENABLE_PROGMEM
+
+namespace ArduinoJson {
+namespace Internals {
+template <>
+struct StringTraits<const __FlashStringHelper*, void> {
+ class Reader {
+ const char* _ptr;
+
+ public:
+ Reader(const __FlashStringHelper* ptr)
+ : _ptr(reinterpret_cast<const char*>(ptr)) {}
+
+ void move() {
+ _ptr++;
+ }
+
+ char current() const {
+ return pgm_read_byte_near(_ptr);
+ }
+
+ char next() const {
+ return pgm_read_byte_near(_ptr + 1);
+ }
+ };
+
+ static bool equals(const __FlashStringHelper* str, const char* expected) {
+ const char* actual = reinterpret_cast<const char*>(str);
+ if (!actual || !expected) return actual == expected;
+ return strcmp_P(expected, actual) == 0;
+ }
+
+ static bool is_null(const __FlashStringHelper* str) {
+ return !str;
+ }
+
+ typedef const char* duplicate_t;
+
+ template <typename Buffer>
+ static duplicate_t duplicate(const __FlashStringHelper* str, Buffer* buffer) {
+ if (!str) return NULL;
+ size_t size = strlen_P((const char*)str) + 1;
+ void* dup = buffer->alloc(size);
+ if (dup != NULL) memcpy_P(dup, (const char*)str, size);
+ return static_cast<duplicate_t>(dup);
+ }
+
+ static const bool has_append = false;
+ static const bool has_equals = true;
+ static const bool should_duplicate = true;
+};
+} // namespace Internals
+} // namespace ArduinoJson
+
+#endif