OLD | NEW |
1 /* | 1 /* |
2 * Copyright © 2011,2012,2014 Google, Inc. | 2 * Copyright © 2011,2012,2014 Google, Inc. |
3 * | 3 * |
4 * This is part of HarfBuzz, a text shaping library. | 4 * This is part of HarfBuzz, a text shaping library. |
5 * | 5 * |
6 * Permission is hereby granted, without written agreement and without | 6 * Permission is hereby granted, without written agreement and without |
7 * license or royalty fees, to use, copy, modify, and distribute this | 7 * license or royalty fees, to use, copy, modify, and distribute this |
8 * software and its documentation for any purpose, provided that the | 8 * software and its documentation for any purpose, provided that the |
9 * above copyright notice and the following two paragraphs appear in | 9 * above copyright notice and the following two paragraphs appear in |
10 * all copies of this software. | 10 * all copies of this software. |
(...skipping 11 matching lines...) Expand all Loading... |
22 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. | 22 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
23 * | 23 * |
24 * Google Author(s): Behdad Esfahbod | 24 * Google Author(s): Behdad Esfahbod |
25 */ | 25 */ |
26 | 26 |
27 #ifndef HB_UTF_PRIVATE_HH | 27 #ifndef HB_UTF_PRIVATE_HH |
28 #define HB_UTF_PRIVATE_HH | 28 #define HB_UTF_PRIVATE_HH |
29 | 29 |
30 #include "hb-private.hh" | 30 #include "hb-private.hh" |
31 | 31 |
32 template <typename T, bool validate=true> struct hb_utf_t; | |
33 | 32 |
| 33 struct hb_utf8_t |
| 34 { |
| 35 typedef uint8_t codepoint_t; |
34 | 36 |
35 /* UTF-8 */ | |
36 | |
37 template <> | |
38 struct hb_utf_t<uint8_t, true> | |
39 { | |
40 static inline const uint8_t * | 37 static inline const uint8_t * |
41 next (const uint8_t *text, | 38 next (const uint8_t *text, |
42 const uint8_t *end, | 39 const uint8_t *end, |
43 hb_codepoint_t *unicode, | 40 hb_codepoint_t *unicode, |
44 hb_codepoint_t replacement) | 41 hb_codepoint_t replacement) |
45 { | 42 { |
46 /* Written to only accept well-formed sequences. | 43 /* Written to only accept well-formed sequences. |
47 * Based on ideas from ICU's U8_NEXT. | 44 * Based on ideas from ICU's U8_NEXT. |
48 * Generates one "replacement" for each ill-formed byte. */ | 45 * Generates one "replacement" for each ill-formed byte. */ |
49 | 46 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 } | 121 } |
125 | 122 |
126 static inline unsigned int | 123 static inline unsigned int |
127 strlen (const uint8_t *text) | 124 strlen (const uint8_t *text) |
128 { | 125 { |
129 return ::strlen ((const char *) text); | 126 return ::strlen ((const char *) text); |
130 } | 127 } |
131 }; | 128 }; |
132 | 129 |
133 | 130 |
134 /* UTF-16 */ | 131 struct hb_utf16_t |
| 132 { |
| 133 typedef uint16_t codepoint_t; |
135 | 134 |
136 template <> | |
137 struct hb_utf_t<uint16_t, true> | |
138 { | |
139 static inline const uint16_t * | 135 static inline const uint16_t * |
140 next (const uint16_t *text, | 136 next (const uint16_t *text, |
141 const uint16_t *end, | 137 const uint16_t *end, |
142 hb_codepoint_t *unicode, | 138 hb_codepoint_t *unicode, |
143 hb_codepoint_t replacement) | 139 hb_codepoint_t replacement) |
144 { | 140 { |
145 hb_codepoint_t c = *text++; | 141 hb_codepoint_t c = *text++; |
146 | 142 |
147 if (likely (!hb_in_range (c, 0xD800u, 0xDFFFu))) | 143 if (likely (!hb_in_range (c, 0xD800u, 0xDFFFu))) |
148 { | 144 { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 static inline unsigned int | 193 static inline unsigned int |
198 strlen (const uint16_t *text) | 194 strlen (const uint16_t *text) |
199 { | 195 { |
200 unsigned int l = 0; | 196 unsigned int l = 0; |
201 while (*text++) l++; | 197 while (*text++) l++; |
202 return l; | 198 return l; |
203 } | 199 } |
204 }; | 200 }; |
205 | 201 |
206 | 202 |
207 /* UTF-32 */ | 203 template <bool validate=true> |
| 204 struct hb_utf32_t |
| 205 { |
| 206 typedef uint32_t codepoint_t; |
208 | 207 |
209 template <bool validate> | |
210 struct hb_utf_t<uint32_t, validate> | |
211 { | |
212 static inline const uint32_t * | 208 static inline const uint32_t * |
213 next (const uint32_t *text, | 209 next (const uint32_t *text, |
214 const uint32_t *end HB_UNUSED, | 210 const uint32_t *end HB_UNUSED, |
215 hb_codepoint_t *unicode, | 211 hb_codepoint_t *unicode, |
216 hb_codepoint_t replacement) | 212 hb_codepoint_t replacement) |
217 { | 213 { |
218 hb_codepoint_t c = *text++; | 214 hb_codepoint_t c = *text++; |
219 if (validate && unlikely (c > 0x10FFFFu || hb_in_range (c, 0xD800u, 0xDFFFu)
)) | 215 if (validate && unlikely (c > 0x10FFFFu || hb_in_range (c, 0xD800u, 0xDFFFu)
)) |
220 goto error; | 216 goto error; |
221 *unicode = c; | 217 *unicode = c; |
(...skipping 17 matching lines...) Expand all Loading... |
239 static inline unsigned int | 235 static inline unsigned int |
240 strlen (const uint32_t *text) | 236 strlen (const uint32_t *text) |
241 { | 237 { |
242 unsigned int l = 0; | 238 unsigned int l = 0; |
243 while (*text++) l++; | 239 while (*text++) l++; |
244 return l; | 240 return l; |
245 } | 241 } |
246 }; | 242 }; |
247 | 243 |
248 | 244 |
| 245 struct hb_latin1_t |
| 246 { |
| 247 typedef uint8_t codepoint_t; |
| 248 |
| 249 static inline const uint8_t * |
| 250 next (const uint8_t *text, |
| 251 const uint8_t *end HB_UNUSED, |
| 252 hb_codepoint_t *unicode, |
| 253 hb_codepoint_t replacement HB_UNUSED) |
| 254 { |
| 255 *unicode = *text++; |
| 256 return text; |
| 257 } |
| 258 |
| 259 static inline const uint8_t * |
| 260 prev (const uint8_t *text, |
| 261 const uint8_t *start HB_UNUSED, |
| 262 hb_codepoint_t *unicode, |
| 263 hb_codepoint_t replacement) |
| 264 { |
| 265 *unicode = *--text; |
| 266 return text; |
| 267 } |
| 268 |
| 269 static inline unsigned int |
| 270 strlen (const uint8_t *text) |
| 271 { |
| 272 unsigned int l = 0; |
| 273 while (*text++) l++; |
| 274 return l; |
| 275 } |
| 276 }; |
| 277 |
249 #endif /* HB_UTF_PRIVATE_HH */ | 278 #endif /* HB_UTF_PRIVATE_HH */ |
OLD | NEW |