OLD | NEW |
1 /* | 1 /* |
2 * The authors of this software are Rob Pike and Ken Thompson. | 2 * The authors of this software are Rob Pike and Ken Thompson. |
3 * Copyright (c) 2002 by Lucent Technologies. | 3 * Copyright (c) 2002 by Lucent Technologies. |
4 * Permission to use, copy, modify, and distribute this software for any | 4 * Permission to use, copy, modify, and distribute this software for any |
5 * purpose without fee is hereby granted, provided that this entire notice | 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 | 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 | 7 * or modification of this software and in all copies of the supporting |
8 * documentation for such software. | 8 * documentation for such software. |
9 * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED | 9 * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED |
10 * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE AN
Y | 10 * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE AN
Y |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 { | 126 { |
127 /* Runes are signed, so convert to unsigned for range check. */ | 127 /* Runes are signed, so convert to unsigned for range check. */ |
128 unsigned long c; | 128 unsigned long c; |
129 | 129 |
130 /* | 130 /* |
131 * one character sequence | 131 * one character sequence |
132 * 00000-0007F => 00-7F | 132 * 00000-0007F => 00-7F |
133 */ | 133 */ |
134 c = *rune; | 134 c = *rune; |
135 if(c <= Rune1) { | 135 if(c <= Rune1) { |
136 » » str[0] = c; | 136 » » str[0] = static_cast<char>(c); |
137 return 1; | 137 return 1; |
138 } | 138 } |
139 | 139 |
140 /* | 140 /* |
141 * two character sequence | 141 * two character sequence |
142 * 0080-07FF => T2 Tx | 142 * 0080-07FF => T2 Tx |
143 */ | 143 */ |
144 if(c <= Rune2) { | 144 if(c <= Rune2) { |
145 » » str[0] = T2 | (c >> 1*Bitx); | 145 » » str[0] = T2 | static_cast<char>(c >> 1*Bitx); |
146 str[1] = Tx | (c & Maskx); | 146 str[1] = Tx | (c & Maskx); |
147 return 2; | 147 return 2; |
148 } | 148 } |
149 | 149 |
150 /* | 150 /* |
151 * If the Rune is out of range, convert it to the error rune. | 151 * If the Rune is out of range, convert it to the error rune. |
152 * Do this test here because the error rune encodes to three bytes. | 152 * Do this test here because the error rune encodes to three bytes. |
153 * Doing it earlier would duplicate work, since an out of range | 153 * Doing it earlier would duplicate work, since an out of range |
154 * Rune wouldn't have fit in one or two bytes. | 154 * Rune wouldn't have fit in one or two bytes. |
155 */ | 155 */ |
156 if (c > Runemax) | 156 if (c > Runemax) |
157 c = Runeerror; | 157 c = Runeerror; |
158 | 158 |
159 /* | 159 /* |
160 * three character sequence | 160 * three character sequence |
161 * 0800-FFFF => T3 Tx Tx | 161 * 0800-FFFF => T3 Tx Tx |
162 */ | 162 */ |
163 if (c <= Rune3) { | 163 if (c <= Rune3) { |
164 » » str[0] = T3 | (c >> 2*Bitx); | 164 » » str[0] = T3 | static_cast<char>(c >> 2*Bitx); |
165 str[1] = Tx | ((c >> 1*Bitx) & Maskx); | 165 str[1] = Tx | ((c >> 1*Bitx) & Maskx); |
166 » » str[2] = Tx | (c & Maskx); | 166 » » str[2] = Tx | (c & Maskx); |
167 return 3; | 167 return 3; |
168 } | 168 } |
169 | 169 |
170 /* | 170 /* |
171 * four character sequence (21-bit value) | 171 * four character sequence (21-bit value) |
172 * 10000-1FFFFF => T4 Tx Tx Tx | 172 * 10000-1FFFFF => T4 Tx Tx Tx |
173 */ | 173 */ |
174 » str[0] = T4 | (c >> 3*Bitx); | 174 » str[0] = T4 | static_cast<char>(c >> 3*Bitx); |
175 str[1] = Tx | ((c >> 2*Bitx) & Maskx); | 175 str[1] = Tx | ((c >> 2*Bitx) & Maskx); |
176 str[2] = Tx | ((c >> 1*Bitx) & Maskx); | 176 str[2] = Tx | ((c >> 1*Bitx) & Maskx); |
177 str[3] = Tx | (c & Maskx); | 177 str[3] = Tx | (c & Maskx); |
178 return 4; | 178 return 4; |
179 } | 179 } |
180 | 180 |
181 int | 181 int |
182 runelen(Rune rune) | 182 runelen(Rune rune) |
183 { | 183 { |
184 char str[10]; | 184 char str[10]; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 } | 249 } |
250 n = chartorune(&r, s); | 250 n = chartorune(&r, s); |
251 if(r == c) | 251 if(r == c) |
252 return (char*)s; | 252 return (char*)s; |
253 s += n; | 253 s += n; |
254 } | 254 } |
255 return 0; | 255 return 0; |
256 } | 256 } |
257 | 257 |
258 } // namespace re2 | 258 } // namespace re2 |
OLD | NEW |