aboutsummaryrefslogtreecommitdiff
path: root/man/u8tor.3
blob: ba081109ef513f0e88d1514006432c724e27eb3a (plain) (blame)
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
.Dd March 10 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
/* Implementation of read_codepoint() omitted */

rune ch;
char8_t *buf = read_codepoint(stdin);
int w = u8tor(&ch, buf);
if (ch == RUNE_ERROR)
	errx("Got invalid UTF-8 codepoint");
printf("Got rune ‘%.*s’\en", w, buf);
.Ed
.Sh SEE ALSO
.Xr errx 3mlib ,
.Xr rtou8 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