blob: 7735ecdd5c600600c6617b00880233cd8bb5f771 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
#ifndef UTF_UTF8_HH
#define UTF_UTF8_HH
#include "macros.hh"
#include <cstdint>
#include <span>
namespace utf {
/**
* 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::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
#endif // UTF_UTF8_HH
|