main
44ceea7 ยท 1 month ago 7 commits
 1#ifndef _SWAY_UNICODE_H
 2#define _SWAY_UNICODE_H
 3#include <stddef.h>
 4#include <stdint.h>
 5
 6// Technically UTF-8 supports up to 6 byte codepoints, but Unicode itself
 7// doesn't really bother with more than 4.
 8#define UTF8_MAX_SIZE 4
 9
10#define UTF8_INVALID 0x80
11
12/**
13 * Gets the size in bytes of the last utf8 character in a NULL terminated string
14 * This function does not validate that the buffer contains correct utf8 data;
15 * it merely looks for the first byte that correctly denotes the beginning of a
16 * utf8 character.
17 */
18int utf8_last_size(const char *str);
19
20/**
21 * Grabs the next UTF-8 character and advances the string pointer
22 */
23uint32_t utf8_decode(const char **str);
24
25/**
26 * Encodes a character as UTF-8 and returns the length of that character.
27 */
28size_t utf8_encode(char *str, uint32_t ch);
29
30/**
31 * Returns the size of the next UTF-8 character
32 */
33int utf8_size(const char *str);
34
35/**
36 * Returns the size of a UTF-8 character
37 */
38size_t utf8_chsize(uint32_t ch);
39
40#endif
41