aboutsummaryrefslogtreecommitdiff
path: root/lib/unicode/string/u8wdth.c
blob: db51b068e125c83d95dceb1a9fa11c13a1117aca (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include "mbstring.h"
#include "unicode/prop.h"
#include "unicode/string.h"

size_t
u8wdth(u8view_t sv, int ts)
{
	rune ch;
	size_t n = 0;

	while (ucsnext(&ch, &sv) != 0) {
		if (ch == '\t')
			n += ts - n % ts;
		else {
			int w = uprop_get_wdth(ch);
			if (w > 0)
				n += w;
		}
	}

	return n;
}