3 .Dt GRAPHEME_ENCODE_UTF8 3
6 .Nm grapheme_encode_utf8
7 .Nd encode codepoint into UTF-8 string
11 .Fn grapheme_encode_utf8 "uint_least32_t cp" "char *str" "size_t len"
14 .Fn grapheme_encode_utf8
15 function encodes the codepoint
24 is large enough it writes the UTF-8-string to the memory pointed to by
26 Otherwise no data is written.
29 .Fn grapheme_encode_utf8
30 function returns the length (in bytes) of the UTF-8-string resulting
35 is not large enough or
41 /* cc (-static) -o example example.c -lgrapheme */
47 cps_to_utf8(const uint_least32_t *cp, size_t cplen, char *str, size_t len)
51 for (i = 0, off = 0; i < cplen; i++, off += ret) {
52 if ((ret = grapheme_encode_utf8(cp[i], str + off,
53 len - off)) > (len - off)) {
54 /* buffer too small */
63 cps_bytelen(const uint_least32_t *cp, size_t cplen)
67 for (i = 0, len = 0; i < cplen; i++) {
68 len += grapheme_encode_utf8(cp[i], NULL, 0);
75 cps_to_utf8_alloc(const uint_least32_t *cp, size_t cplen)
78 size_t len, i, ret, off;
80 len = cps_bytelen(cp, cplen);
82 if (!(str = malloc(len))) {
86 for (i = 0, off = 0; i < cplen; i++, off += ret) {
87 if ((ret = grapheme_encode_utf8(cp[i], str + off,
88 len - off)) > (len - off)) {
89 /* buffer too small */
99 .Xr grapheme_decode_utf8 3 ,
102 .An Laslo Hunhold Aq Mt dev@frign.de