diff options
Diffstat (limited to 'include/lib/ArduinoJson/Json/Utf8.hpp')
-rw-r--r-- | include/lib/ArduinoJson/Json/Utf8.hpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/include/lib/ArduinoJson/Json/Utf8.hpp b/include/lib/ArduinoJson/Json/Utf8.hpp new file mode 100644 index 0000000..a30f77a --- /dev/null +++ b/include/lib/ArduinoJson/Json/Utf8.hpp @@ -0,0 +1,46 @@ +// ArduinoJson - https://arduinojson.org +// Copyright Benoit Blanchon 2014-2021 +// MIT License + +#pragma once + +#include <ArduinoJson/Namespace.hpp> + +namespace ARDUINOJSON_NAMESPACE { + +namespace Utf8 { +template <typename TStringBuilder> +inline void encodeCodepoint(uint32_t codepoint32, TStringBuilder& str) { + // this function was optimize for code size on AVR + + // a buffer to store the string in reverse + char buf[5]; + char* p = buf; + + *(p++) = 0; + if (codepoint32 < 0x80) { + *(p++) = char((codepoint32)); + } else { + *(p++) = char((codepoint32 | 0x80) & 0xBF); + uint16_t codepoint16 = uint16_t(codepoint32 >> 6); + if (codepoint16 < 0x20) { // 0x800 + *(p++) = char(codepoint16 | 0xC0); + } else { + *(p++) = char((codepoint16 | 0x80) & 0xBF); + codepoint16 = uint16_t(codepoint16 >> 6); + if (codepoint16 < 0x10) { // 0x10000 + *(p++) = char(codepoint16 | 0xE0); + } else { + *(p++) = char((codepoint16 | 0x80) & 0xBF); + codepoint16 = uint16_t(codepoint16 >> 6); + *(p++) = char(codepoint16 | 0xF0); + } + } + } + + while (*(--p)) { + str.append(*p); + } +} +} // namespace Utf8 +} // namespace ARDUINOJSON_NAMESPACE |