2
* The authors of this software are Rob Pike and Ken Thompson.
3
* Copyright (c) 2002 by Lucent Technologies.
4
* Permission to use, copy, modify, and distribute this software for any
5
* purpose without fee is hereby granted, provided that this entire notice
6
* is included in all copies of any software which is or includes a copy
7
* or modification of this software and in all copies of the supporting
8
* documentation for such software.
9
* THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
10
* WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE
11
* ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
12
* OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
27
T1 = ((1<<(Bit1+1))-1) ^ 0xFF, /* 0000 0000 */
28
Tx = ((1<<(Bitx+1))-1) ^ 0xFF, /* 1000 0000 */
29
T2 = ((1<<(Bit2+1))-1) ^ 0xFF, /* 1100 0000 */
30
T3 = ((1<<(Bit3+1))-1) ^ 0xFF, /* 1110 0000 */
31
T4 = ((1<<(Bit4+1))-1) ^ 0xFF, /* 1111 0000 */
33
Rune1 = (1<<(Bit1+0*Bitx))-1, /* 0000 0000 0111 1111 */
34
Rune2 = (1<<(Bit2+1*Bitx))-1, /* 0000 0111 1111 1111 */
35
Rune3 = (1<<(Bit3+2*Bitx))-1, /* 1111 1111 1111 1111 */
37
Maskx = (1<<Bitx)-1, /* 0011 1111 */
38
Testx = Maskx ^ 0xFF, /* 1100 0000 */
44
chartorune(Rune *rune, char *str)
50
* one character sequence
60
* two character sequence
63
c1 = *(uchar*)(str+1) ^ Tx;
69
l = ((c << Bitx) | c1) & Rune2;
77
* three character sequence
78
* 0800-FFFF => T3 Tx Tx
80
c2 = *(uchar*)(str+2) ^ Tx;
84
l = ((((c << Bitx) | c1) << Bitx) | c2) & Rune3;
100
runetochar(char *str, Rune *rune)
105
* one character sequence
106
* 00000-0007F => 00-7F
115
* two character sequence
119
str[0] = T2 | (c >> 1*Bitx);
120
str[1] = Tx | (c & Maskx);
125
* three character sequence
126
* 0800-FFFF => T3 Tx Tx
128
str[0] = T3 | (c >> 2*Bitx);
129
str[1] = Tx | ((c >> 1*Bitx) & Maskx);
130
str[2] = Tx | (c & Maskx);
141
return runetochar(str, &rune);
145
runenlen(Rune *r, int nrune)
164
fullrune(char *str, int n)