OLD | NEW |
---|---|
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #ifndef VM_UNICODE_H_ | 5 #ifndef VM_UNICODE_H_ |
6 #define VM_UNICODE_H_ | 6 #define VM_UNICODE_H_ |
7 | 7 |
8 #include "vm/allocation.h" | 8 #include "vm/allocation.h" |
9 #include "vm/globals.h" | 9 #include "vm/globals.h" |
10 | 10 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
86 // Returns true if ch is a lead surrogate. | 86 // Returns true if ch is a lead surrogate. |
87 static bool IsLeadSurrogate(int32_t ch) { | 87 static bool IsLeadSurrogate(int32_t ch) { |
88 return (ch & 0xFFFFFC00) == 0xD800; | 88 return (ch & 0xFFFFFC00) == 0xD800; |
89 } | 89 } |
90 | 90 |
91 // Returns true if ch is a low surrogate. | 91 // Returns true if ch is a low surrogate. |
92 static bool IsTrailSurrogate(int32_t ch) { | 92 static bool IsTrailSurrogate(int32_t ch) { |
93 return (ch & 0xFFFFFC00) == 0xDC00; | 93 return (ch & 0xFFFFFC00) == 0xDC00; |
94 } | 94 } |
95 | 95 |
96 // Returns the character at i and advances i to the next character | |
97 // boundary. | |
98 static int32_t Next(const uint16_t* characters, intptr_t* i, intptr_t len) { | |
99 int32_t ch = characters[*i]; | |
100 if (Utf16::IsLeadSurrogate(ch) && (*i < (len - 1))) { | |
101 int32_t ch2 = characters[*i + 1]; | |
102 if (Utf16::IsTrailSurrogate(ch2)) { | |
103 ch = Utf16::Decode(ch, ch2); | |
104 *i += 2; | |
105 } | |
106 } else { | |
107 *i += 1; | |
108 } | |
109 return ch; | |
110 } | |
siva
2012/11/30 02:00:19
I am wondering if it would make sense to add an it
cshapiro
2012/11/30 02:28:22
Hmm... the code point iterator is rather bulky. I
| |
111 | |
96 // Decodes a surrogate pair into a supplementary code point. | 112 // Decodes a surrogate pair into a supplementary code point. |
97 static int32_t Decode(int32_t lead, int32_t trail) { | 113 static int32_t Decode(int32_t lead, int32_t trail) { |
98 return 0x10000 + ((lead & 0x3FF) << 10) + (trail & 0x3FF); | 114 return 0x10000 + ((lead & 0x3FF) << 10) + (trail & 0x3FF); |
99 } | 115 } |
100 | 116 |
101 // Encodes a single code point. | 117 // Encodes a single code point. |
102 static void Encode(int32_t codepoint, uint16_t* dst); | 118 static void Encode(int32_t codepoint, uint16_t* dst); |
103 }; | 119 }; |
104 | 120 |
105 | 121 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
162 // Data for small code points with one mapping | 178 // Data for small code points with one mapping |
163 static const int16_t stage2_[]; | 179 static const int16_t stage2_[]; |
164 | 180 |
165 // Data for large code points or code points with both mappings. | 181 // Data for large code points or code points with both mappings. |
166 static const int32_t stage2_exception_[][2]; | 182 static const int32_t stage2_exception_[][2]; |
167 }; | 183 }; |
168 | 184 |
169 } // namespace dart | 185 } // namespace dart |
170 | 186 |
171 #endif // VM_UNICODE_H_ | 187 #endif // VM_UNICODE_H_ |
OLD | NEW |