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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 SkASSERT(utf8); | 67 SkASSERT(utf8); |
68 | 68 |
69 const uint8_t* p = (const uint8_t*)utf8; | 69 const uint8_t* p = (const uint8_t*)utf8; |
70 int c = *p; | 70 int c = *p; |
71 int hic = c << 24; | 71 int hic = c << 24; |
72 | 72 |
73 assert_utf8_leadingbyte(c); | 73 assert_utf8_leadingbyte(c); |
74 | 74 |
75 if (hic < 0) { | 75 if (hic < 0) { |
76 uint32_t mask = (uint32_t)~0x3F; | 76 uint32_t mask = (uint32_t)~0x3F; |
77 hic <<= 1; | 77 hic = SkLeftShift(hic, 1); |
78 do { | 78 do { |
79 c = (c << 6) | (*++p & 0x3F); | 79 c = (c << 6) | (*++p & 0x3F); |
80 mask <<= 5; | 80 mask <<= 5; |
81 } while ((hic <<= 1) < 0); | 81 } while ((hic = SkLeftShift(hic, 1)) < 0); |
82 c &= ~mask; | 82 c &= ~mask; |
83 } | 83 } |
84 return c; | 84 return c; |
85 } | 85 } |
86 | 86 |
87 SkUnichar SkUTF8_NextUnichar(const char** ptr) { | 87 SkUnichar SkUTF8_NextUnichar(const char** ptr) { |
88 SkASSERT(ptr && *ptr); | 88 SkASSERT(ptr && *ptr); |
89 | 89 |
90 const uint8_t* p = (const uint8_t*)*ptr; | 90 const uint8_t* p = (const uint8_t*)*ptr; |
91 int c = *p; | 91 int c = *p; |
92 int hic = c << 24; | 92 int hic = c << 24; |
93 | 93 |
94 assert_utf8_leadingbyte(c); | 94 assert_utf8_leadingbyte(c); |
95 | 95 |
96 if (hic < 0) { | 96 if (hic < 0) { |
97 uint32_t mask = (uint32_t)~0x3F; | 97 uint32_t mask = (uint32_t)~0x3F; |
98 hic <<= 1; | 98 hic = SkLeftShift(hic, 1); |
99 do { | 99 do { |
100 c = (c << 6) | (*++p & 0x3F); | 100 c = (c << 6) | (*++p & 0x3F); |
101 mask <<= 5; | 101 mask <<= 5; |
102 } while ((hic <<= 1) < 0); | 102 } while ((hic = SkLeftShift(hic, 1)) < 0); |
103 c &= ~mask; | 103 c &= ~mask; |
104 } | 104 } |
105 *ptr = (char*)p + 1; | 105 *ptr = (char*)p + 1; |
106 return c; | 106 return c; |
107 } | 107 } |
108 | 108 |
109 SkUnichar SkUTF8_PrevUnichar(const char** ptr) { | 109 SkUnichar SkUTF8_PrevUnichar(const char** ptr) { |
110 SkASSERT(ptr && *ptr); | 110 SkASSERT(ptr && *ptr); |
111 | 111 |
112 const char* p = *ptr; | 112 const char* p = *ptr; |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 } | 271 } |
272 } else { | 272 } else { |
273 char* start = utf8; | 273 char* start = utf8; |
274 while (utf16 < stop) { | 274 while (utf16 < stop) { |
275 utf8 += SkUTF8_FromUnichar(SkUTF16_NextUnichar(&utf16), utf8); | 275 utf8 += SkUTF8_FromUnichar(SkUTF16_NextUnichar(&utf16), utf8); |
276 } | 276 } |
277 size = utf8 - start; | 277 size = utf8 - start; |
278 } | 278 } |
279 return size; | 279 return size; |
280 } | 280 } |
OLD | NEW |