diff options
Diffstat (limited to 'utf/inc/utf8.hh')
| -rw-r--r-- | utf/inc/utf8.hh | 19 |
1 files changed, 15 insertions, 4 deletions
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 |
