| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 | 9 |
| 10 #include "SkUtils.h" | 10 #include "SkUtils.h" |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 if (c == 0) { | 186 if (c == 0) { |
| 187 break; | 187 break; |
| 188 } | 188 } |
| 189 utf8 += SkUTF8_LeadByteToCount(c); | 189 utf8 += SkUTF8_LeadByteToCount(c); |
| 190 count += 1; | 190 count += 1; |
| 191 } | 191 } |
| 192 return count; | 192 return count; |
| 193 } | 193 } |
| 194 | 194 |
| 195 int SkUTF8_CountUnichars(const char utf8[], size_t byteLength) { | 195 int SkUTF8_CountUnichars(const char utf8[], size_t byteLength) { |
| 196 SkASSERT(NULL != utf8 || 0 == byteLength); | 196 SkASSERT(utf8 || 0 == byteLength); |
| 197 | 197 |
| 198 int count = 0; | 198 int count = 0; |
| 199 const char* stop = utf8 + byteLength; | 199 const char* stop = utf8 + byteLength; |
| 200 | 200 |
| 201 while (utf8 < stop) { | 201 while (utf8 < stop) { |
| 202 utf8 += SkUTF8_LeadByteToCount(*(const uint8_t*)utf8); | 202 utf8 += SkUTF8_LeadByteToCount(*(const uint8_t*)utf8); |
| 203 count += 1; | 203 count += 1; |
| 204 } | 204 } |
| 205 return count; | 205 return count; |
| 206 } | 206 } |
| 207 | 207 |
| 208 SkUnichar SkUTF8_ToUnichar(const char utf8[]) { | 208 SkUnichar SkUTF8_ToUnichar(const char utf8[]) { |
| 209 SkASSERT(NULL != utf8); | 209 SkASSERT(utf8); |
| 210 | 210 |
| 211 const uint8_t* p = (const uint8_t*)utf8; | 211 const uint8_t* p = (const uint8_t*)utf8; |
| 212 int c = *p; | 212 int c = *p; |
| 213 int hic = c << 24; | 213 int hic = c << 24; |
| 214 | 214 |
| 215 assert_utf8_leadingbyte(c); | 215 assert_utf8_leadingbyte(c); |
| 216 | 216 |
| 217 if (hic < 0) { | 217 if (hic < 0) { |
| 218 uint32_t mask = (uint32_t)~0x3F; | 218 uint32_t mask = (uint32_t)~0x3F; |
| 219 hic <<= 1; | 219 hic <<= 1; |
| 220 do { | 220 do { |
| 221 c = (c << 6) | (*++p & 0x3F); | 221 c = (c << 6) | (*++p & 0x3F); |
| 222 mask <<= 5; | 222 mask <<= 5; |
| 223 } while ((hic <<= 1) < 0); | 223 } while ((hic <<= 1) < 0); |
| 224 c &= ~mask; | 224 c &= ~mask; |
| 225 } | 225 } |
| 226 return c; | 226 return c; |
| 227 } | 227 } |
| 228 | 228 |
| 229 SkUnichar SkUTF8_NextUnichar(const char** ptr) { | 229 SkUnichar SkUTF8_NextUnichar(const char** ptr) { |
| 230 SkASSERT(NULL != ptr && NULL != *ptr); | 230 SkASSERT(ptr && *ptr); |
| 231 | 231 |
| 232 const uint8_t* p = (const uint8_t*)*ptr; | 232 const uint8_t* p = (const uint8_t*)*ptr; |
| 233 int c = *p; | 233 int c = *p; |
| 234 int hic = c << 24; | 234 int hic = c << 24; |
| 235 | 235 |
| 236 assert_utf8_leadingbyte(c); | 236 assert_utf8_leadingbyte(c); |
| 237 | 237 |
| 238 if (hic < 0) { | 238 if (hic < 0) { |
| 239 uint32_t mask = (uint32_t)~0x3F; | 239 uint32_t mask = (uint32_t)~0x3F; |
| 240 hic <<= 1; | 240 hic <<= 1; |
| 241 do { | 241 do { |
| 242 c = (c << 6) | (*++p & 0x3F); | 242 c = (c << 6) | (*++p & 0x3F); |
| 243 mask <<= 5; | 243 mask <<= 5; |
| 244 } while ((hic <<= 1) < 0); | 244 } while ((hic <<= 1) < 0); |
| 245 c &= ~mask; | 245 c &= ~mask; |
| 246 } | 246 } |
| 247 *ptr = (char*)p + 1; | 247 *ptr = (char*)p + 1; |
| 248 return c; | 248 return c; |
| 249 } | 249 } |
| 250 | 250 |
| 251 SkUnichar SkUTF8_PrevUnichar(const char** ptr) { | 251 SkUnichar SkUTF8_PrevUnichar(const char** ptr) { |
| 252 SkASSERT(NULL != ptr && NULL != *ptr); | 252 SkASSERT(ptr && *ptr); |
| 253 | 253 |
| 254 const char* p = *ptr; | 254 const char* p = *ptr; |
| 255 | 255 |
| 256 if (*--p & 0x80) { | 256 if (*--p & 0x80) { |
| 257 while (*--p & 0x40) { | 257 while (*--p & 0x40) { |
| 258 ; | 258 ; |
| 259 } | 259 } |
| 260 } | 260 } |
| 261 | 261 |
| 262 *ptr = (char*)p; | 262 *ptr = (char*)p; |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 } | 413 } |
| 414 } else { | 414 } else { |
| 415 char* start = utf8; | 415 char* start = utf8; |
| 416 while (utf16 < stop) { | 416 while (utf16 < stop) { |
| 417 utf8 += SkUTF8_FromUnichar(SkUTF16_NextUnichar(&utf16), utf8); | 417 utf8 += SkUTF8_FromUnichar(SkUTF16_NextUnichar(&utf16), utf8); |
| 418 } | 418 } |
| 419 size = utf8 - start; | 419 size = utf8 - start; |
| 420 } | 420 } |
| 421 return size; | 421 return size; |
| 422 } | 422 } |
| OLD | NEW |