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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
#define UNICODE
#define Unknown win_Unknown
#include <windows.h>
#include <winbase.h>
#undef Unknown
#undef Sleep
#include "dat.h"
#include "fns.h"
#include "error.h"
#include "r16.h"
Rune16*
runesdup(Rune16 *r)
{
int n;
Rune16 *s;
n = runeslen(r) + 1;
s = malloc(n * sizeof(Rune16));
if(s == nil)
error(Enomem);
memmove(s, r, n * sizeof(Rune16));
return s;
}
int
runeslen(Rune16 *r)
{
int n;
n = 0;
while(*r++ != 0)
n++;
return n;
}
char*
runestoutf(char *p, Rune16 *r, int nc)
{
char *op, *ep;
int n, c;
Rune rc;
op = p;
ep = p + nc;
while(c = *r++) {
n = 1;
if(c >= Runeself)
n = runelen(c);
if(p + n >= ep)
break;
rc = c;
if(c < Runeself)
*p++ = c;
else
p += runetochar(p, &rc);
}
*p = '\0';
return op;
}
Rune16*
utftorunes(Rune16 *r, char *p, int nc)
{
Rune16 *or, *er;
Rune rc;
or = r;
er = r + nc;
while(*p != '\0' && r + 1 < er){
p += chartorune(&rc, p);
*r++ = rc; /* we'll ignore surrogate pairs */
}
*r = '\0';
return or;
}
int
runescmp(Rune16 *s1, Rune16 *s2)
{
Rune16 r1, r2;
for(;;) {
r1 = *s1++;
r2 = *s2++;
if(r1 != r2) {
if(r1 > r2)
return 1;
return -1;
}
if(r1 == 0)
return 0;
}
}
|