diff options
| author | Joel Klinghed <the_jk@spawned.biz> | 2024-01-21 12:31:30 +0100 |
|---|---|---|
| committer | Joel Klinghed <the_jk@spawned.biz> | 2024-01-21 12:31:30 +0100 |
| commit | 7dd49c6293172b494c78918507242cdb55d35137 (patch) | |
| tree | 9c8ab822ab9501a5ea2f937e609144e00ea091c4 /utf/inc | |
| parent | fc4547b412e28164af1bf8981234c6af959ccc0b (diff) | |
WIP
Diffstat (limited to 'utf/inc')
| -rw-r--r-- | utf/inc/utf16.hh | 12 | ||||
| -rw-r--r-- | utf/inc/utf32.hh | 12 | ||||
| -rw-r--r-- | utf/inc/utf8.hh | 19 |
3 files changed, 29 insertions, 14 deletions
diff --git a/utf/inc/utf16.hh b/utf/inc/utf16.hh index 344b1a2..b9229bc 100644 --- a/utf/inc/utf16.hh +++ b/utf/inc/utf16.hh @@ -4,27 +4,29 @@ #include "macros.hh" #include <cstdint> -#include <string_view> +#include <span> namespace utf { -/* Read one unicode codepoint from UTF-16 BigEndian encoded data if possible. +/** + * Read one unicode codepoint from UTF-16 BigEndian encoded data if possible. * If successfull offset is incremented to point to next codepoint. * Will fail: * - not enough data is left in data given offset, returns NEED_MORE. * - data is not valid UTF-16, ie. invalid or incomplete surrogate pairs, * returns INVALID. */ -uint32_t HIDDEN read16be(std::string_view data, std::size_t& offset); +uint32_t HIDDEN read16be(std::span<uint8_t const> data, std::size_t& offset); -/* Read one unicode codepoint from UTF-16 LittleEndian encoded data if possible. +/** + * Read one unicode codepoint from UTF-16 LittleEndian encoded data if possible. * If successfull offset is incremented to point to next codepoint. * Will fail: * - not enough data is left in data given offset, returns NEED_MORE. * - data is not valid UTF-16, ie. invalid or incomplete surrogate pairs, * returns INVALID. */ -uint32_t HIDDEN read16le(std::string_view data, std::size_t& offset); +uint32_t HIDDEN read16le(std::span<uint8_t const> data, std::size_t& offset); } // namespace utf diff --git a/utf/inc/utf32.hh b/utf/inc/utf32.hh index 2d3088e..4ee5eac 100644 --- a/utf/inc/utf32.hh +++ b/utf/inc/utf32.hh @@ -4,25 +4,27 @@ #include "macros.hh" #include <cstdint> -#include <string_view> +#include <span> namespace utf { -/* Read one unicode codepoint from UTF-32 BigEndian encoded data if possible. +/** + * Read one unicode codepoint from UTF-32 BigEndian encoded data if possible. * If successfull offset is incremented to point to next codepoint. * Will fail: * - not enough data is left in data given offset, returns NEED_MORE. * - data is not valid UTF-32, ie. outside valid ranges, returns INVALID. */ -uint32_t HIDDEN read32be(std::string_view data, std::size_t& offset); +uint32_t HIDDEN read32be(std::span<uint8_t const> data, std::size_t& offset); -/* Read one unicode codepoint from UTF-32 LittleEndian encoded data if possible. +/** + * Read one unicode codepoint from UTF-32 LittleEndian encoded data if possible. * If successfull offset is incremented to point to next codepoint. * Will fail: * - not enough data is left in data given offset, returns NEED_MORE. * - data is not valid UTF-32, ie. outside valid ranges, returns INVALID. */ -uint32_t HIDDEN read32le(std::string_view data, std::size_t& offset); +uint32_t HIDDEN read32le(std::span<uint8_t const> data, std::size_t& offset); } // namespace utf diff --git a/utf/inc/utf8.hh b/utf/inc/utf8.hh index a3ea84a..7735ecd 100644 --- a/utf/inc/utf8.hh +++ b/utf/inc/utf8.hh @@ -4,18 +4,29 @@ #include "macros.hh" #include <cstdint> -#include <string_view> +#include <span> namespace utf { -/* Read one unicode codepoint from UTF-8 encoded data if possible. - * If successfull offset is incremented to point to next codepoint. +/** + * Read one unicode codepoint from UTF-8 encoded data if possible. + * If successful, offset is incremented to point to next codepoint. * Will fail: * - not enough data is left in data given offset, returns NEED_MORE. * - data is not valid UTF-8, this includes overlong encodings and * invalid unicode code points, returns INVALID. */ -uint32_t HIDDEN read8(std::string_view data, std::size_t& offset); +uint32_t HIDDEN read8(std::span<uint8_t const> data, std::size_t& offset); + +/** + * Write one unicode codepoint to UTF-8 encoded data if possible. + * If successful, offset is incremented to the end of the written data + * and true is returned. + * If not successful, offset is not incremented and false is returned. + * data is not modified. + */ +bool HIDDEN write8(uint32_t codepoint, std::span<uint8_t> data, + std::size_t& offset); } // namespace utf |
