| 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 += 1; |
| 105 } |
| 106 } |
| 107 *i += 1; |
| 108 return ch; |
| 109 } |
| 110 |
| 96 // Decodes a surrogate pair into a supplementary code point. | 111 // Decodes a surrogate pair into a supplementary code point. |
| 97 static int32_t Decode(int32_t lead, int32_t trail) { | 112 static int32_t Decode(int32_t lead, int32_t trail) { |
| 98 return 0x10000 + ((lead & 0x3FF) << 10) + (trail & 0x3FF); | 113 return 0x10000 + ((lead & 0x3FF) << 10) + (trail & 0x3FF); |
| 99 } | 114 } |
| 100 | 115 |
| 101 // Encodes a single code point. | 116 // Encodes a single code point. |
| 102 static void Encode(int32_t codepoint, uint16_t* dst); | 117 static void Encode(int32_t codepoint, uint16_t* dst); |
| 103 }; | 118 }; |
| 104 | 119 |
| 105 | 120 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 // Data for small code points with one mapping | 177 // Data for small code points with one mapping |
| 163 static const int16_t stage2_[]; | 178 static const int16_t stage2_[]; |
| 164 | 179 |
| 165 // Data for large code points or code points with both mappings. | 180 // Data for large code points or code points with both mappings. |
| 166 static const int32_t stage2_exception_[][2]; | 181 static const int32_t stage2_exception_[][2]; |
| 167 }; | 182 }; |
| 168 | 183 |
| 169 } // namespace dart | 184 } // namespace dart |
| 170 | 185 |
| 171 #endif // VM_UNICODE_H_ | 186 #endif // VM_UNICODE_H_ |
| OLD | NEW |