blob: c580027a4aec55f8c8065925c18d2826c03ecac6 (
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
|
/*
Copyright 2022-2023 Gabriel Jensen.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
#include <zp/str.h>
zp_siz zp_utf8enclen(zp_c02 const * str) {
zp_siz len = 0x0u;
for (;;++str) {
zp_c02 const chr = *str;
if (chr >= 0x10000u) {
len += 0x4u;
continue;
}
if (chr >= 0x800u) {
len += 0x3u;
continue;
}
if (chr >= 0x80u) {
len += 0x2u;
continue;
}
zp_ulik (chr == 0x0u) {break;}
++len;
}
return len;
}
|