Subversion Repositories planix.SVN

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 1
#include <u.h>
2
#include <libc.h>
3
 
4
int
5
wstrutflen(Rune *s)
6
{
7
	int n;
8
 
9
	for(n=0; *s; n+=runelen(*s),s++)
10
		;
11
	return n;
12
}
13
 
14
int
15
wstrtoutf(char *s, Rune *t, int n)
16
{
17
	int i;
18
	char *s0;
19
 
20
	s0 = s;
21
	if(n <= 0)
22
		return wstrutflen(t)+1;
23
	while(*t) {
24
		if(n < UTFmax+1 && n < runelen(*t)+1) {
25
			*s = 0;
26
			return i+wstrutflen(t)+1;
27
		}
28
		i = runetochar(s, t);
29
		s += i;
30
		n -= i;
31
		t++;
32
	}
33
	*s = 0;
34
	return s-s0;
35
}