summaryrefslogtreecommitdiff
path: root/zp/source/any/str/utf8declen.c
blob: bde4a749e5d00f8c1be47ba6182dcbdfd3ffdd90 (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_utf8declen(zp_c8 const * str) {
	zp_siz len = 0x0u;

	for (;;++len) {
		zp_c8 const oct = *str;
		
		zp_ulik (oct == 0x0u) {break;}

		if (oct >= 0xF0u) {
			str += 0x4u;
			continue;
		}

		if (oct >= 0xE0u) {
			str += 0x3u;
			continue;
		}

		if (oct >= 0xC0u) {
			str += 0x2u;
			continue;
		}
		
		++str;
	}

	return len;
}