a
This commit is contained in:
35
gui-win32/wstrtoutf.c
Normal file
35
gui-win32/wstrtoutf.c
Normal file
@@ -0,0 +1,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;
|
||||
}
|
Reference in New Issue
Block a user