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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
66 | 66 |
67 | 67 |
68 class Utf16 : AllStatic { | 68 class Utf16 : AllStatic { |
69 public: | 69 public: |
70 static const int32_t kMaxBmpCodepoint = 0xFFFF; | 70 static const int32_t kMaxBmpCodepoint = 0xFFFF; |
71 | 71 |
72 static const int32_t kLeadSurrogateOffset = (0xD800 - (0x10000 >> 10)); | 72 static const int32_t kLeadSurrogateOffset = (0xD800 - (0x10000 >> 10)); |
73 | 73 |
74 static const int32_t kSurrogateOffset = (0x10000 - (0xD800 << 10) - 0xDC00); | 74 static const int32_t kSurrogateOffset = (0x10000 - (0xD800 << 10) - 0xDC00); |
75 | 75 |
76 class CodePointIterator { | |
cshapiro
2012/11/30 02:49:08
Consider Utf16::Next, which is a lighter-weight, a
Søren Gjesse
2012/11/30 12:23:07
Are you suggestion a static function like this:
bo
Søren Gjesse
2012/11/30 13:06:03
I didn't realize that Utf16::Next was already in t
| |
77 public: | |
78 CodePointIterator(const uint16_t* utf16_array, intptr_t array_len) | |
79 : utf16_array_(utf16_array), | |
80 array_len_(array_len), | |
81 index_(-1), | |
82 ch_(-1) { | |
83 } | |
84 | |
85 int32_t Current() const { | |
86 ASSERT(index_ >= 0); | |
87 ASSERT(index_ < array_len_); | |
88 return ch_; | |
89 } | |
90 | |
91 bool Next(); | |
92 | |
93 void Reset() { | |
94 index_ = -1; | |
95 ch_ = -1; | |
96 } | |
97 | |
98 private: | |
99 const uint16_t* utf16_array_; | |
100 intptr_t array_len_; | |
101 intptr_t index_; | |
102 int32_t ch_; | |
103 DISALLOW_IMPLICIT_CONSTRUCTORS(CodePointIterator); | |
104 }; | |
105 | |
76 // Returns the length of the code point in UTF-16 code units. | 106 // Returns the length of the code point in UTF-16 code units. |
77 static intptr_t Length(int32_t ch) { | 107 static intptr_t Length(int32_t ch) { |
78 return (ch <= kMaxBmpCodepoint) ? 1 : 2; | 108 return (ch <= kMaxBmpCodepoint) ? 1 : 2; |
79 } | 109 } |
80 | 110 |
81 // Returns true if ch is a lead or trail surrogate. | 111 // Returns true if ch is a lead or trail surrogate. |
82 static bool IsSurrogate(int32_t ch) { | 112 static bool IsSurrogate(int32_t ch) { |
83 return (ch & 0xFFFFF800) == 0xD800; | 113 return (ch & 0xFFFFF800) == 0xD800; |
84 } | 114 } |
85 | 115 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
162 // Data for small code points with one mapping | 192 // Data for small code points with one mapping |
163 static const int16_t stage2_[]; | 193 static const int16_t stage2_[]; |
164 | 194 |
165 // Data for large code points or code points with both mappings. | 195 // Data for large code points or code points with both mappings. |
166 static const int32_t stage2_exception_[][2]; | 196 static const int32_t stage2_exception_[][2]; |
167 }; | 197 }; |
168 | 198 |
169 } // namespace dart | 199 } // namespace dart |
170 | 200 |
171 #endif // VM_UNICODE_H_ | 201 #endif // VM_UNICODE_H_ |
OLD | NEW |