// ArduinoJson - arduinojson.org // Copyright Benoit Blanchon 2014-2018 // MIT License #pragma once #include // strcmp namespace ARDUINOJSON_NAMESPACE { class FixedSizeRamString { public: FixedSizeRamString(const char* str, size_t n) : _str(str), _size(n) {} bool equals(const char* expected) const { const char* actual = reinterpret_cast(_str); if (!actual || !expected) return actual == expected; return strcmp(actual, expected) == 0; } bool isNull() const { return !_str; } template StringSlot* save(TMemoryPool* memoryPool) const { if (!_str) return NULL; StringSlot* slot = memoryPool->allocFrozenString(_size); if (slot) memcpy(slot->value, _str, _size); return slot; } size_t size() const { return strlen(reinterpret_cast(_str)); } private: const char* _str; size_t _size; }; template inline FixedSizeRamString makeString(const TChar* str, size_t size) { return FixedSizeRamString(reinterpret_cast(str), size); } } // namespace ARDUINOJSON_NAMESPACE