blob: 2cdc7fd8b7e8abc35dc24a32775ecb121f17590b (
plain)
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
|
#include <u.h>
#include <libc.h>
int
wstrutflen(Rune *s)
{
int n;
for(n=0; *s; n+=runelen(*s),s++)
;
return n;
}
int
wstrtoutf(char *s, Rune *t, int n)
{
int i;
char *s0;
s0 = s;
if(n <= 0)
return wstrutflen(t)+1;
while(*t) {
if(n < UTFmax+1 && n < runelen(*t)+1) {
*s = 0;
return i+wstrutflen(t)+1;
}
i = runetochar(s, t);
s += i;
n -= i;
t++;
}
*s = 0;
return s-s0;
}
|