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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
.Dd 4 May 2024
.Dt U8TOR 3
.Os
.Sh NAME
.Nm u8tor
.Nd decode UTF-8 into a rune
.Sh LIBRARY
.Lb mlib
.Sh SYNOPSIS
.In mbstring.h
.Ft int
.Fn u8tor "rune *ch" "const char8_t *s"
.Sh DESCRIPTION
The
.Fn u8tor
function decodes the first rune in the UTF-8 buffer
.Fa s ,
storing the result in the rune pointed to by
.Fa ch
and returns the number of bytes which compose the decoded
UTF-8.
.Pp
If attempting to decode an invalid byte,
.Va *ch
will be set to
.Dv RUNE_ERROR.
.Sh RETURN VALUES
The
.Fn u8tor
function returns the number of bytes from
.Fa s
decoded into
.Fa ch .
.Sh EXAMPLES
The following call to
.Fn u8tor
attempts to decode the first UTF-8 codepoint in
.Va buf .
.Bd -literal -offset indent
#include <errors.h> /* For err(); see errors(3) */
#include <rune.h> /* For PRIXRUNE; see rune(3) */
rune ch;
char8_t *buf = u8"Γειά σου Κόσμε";
int w = u8tor(&ch, buf);
if (ch == RUNE_ERROR)
err("Got invalid UTF-8 codepoint");
printf("Got rune ‘%.*s’ (U+%04" PRIXRUNE ")\en", w, buf, ch);
.Ed
.Sh SEE ALSO
.Xr errors 3 ,
.Xr rtou8 3 ,
.Xr rune 3 ,
.Xr u8chk 3 ,
.Xr u8next 3 ,
.Xr RUNE_ERROR 3const ,
.Xr unicode 7 ,
.Xr utf\-8 7
.Sh STANDARDS
.Rs
.%A F. Yergeau
.%D November 2003
.%R RFC 3629
.%T UTF-8, a transformation format of ISO 10646
.Re
.Sh AUTHORS
.An Thomas Voss Aq Mt mail@thomasvoss.com
|