Chromium Code Reviews| Index: runtime/vm/unicode.h |
| diff --git a/runtime/vm/unicode.h b/runtime/vm/unicode.h |
| index 03a4b29d879898c2c83f06aac4a175d4729db209..68747fa969a32eb82d87a6a65e2736cb98a861d3 100644 |
| --- a/runtime/vm/unicode.h |
| +++ b/runtime/vm/unicode.h |
| @@ -73,6 +73,36 @@ class Utf16 : AllStatic { |
| static const int32_t kSurrogateOffset = (0x10000 - (0xD800 << 10) - 0xDC00); |
| + 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
|
| + public: |
| + CodePointIterator(const uint16_t* utf16_array, intptr_t array_len) |
| + : utf16_array_(utf16_array), |
| + array_len_(array_len), |
| + index_(-1), |
| + ch_(-1) { |
| + } |
| + |
| + int32_t Current() const { |
| + ASSERT(index_ >= 0); |
| + ASSERT(index_ < array_len_); |
| + return ch_; |
| + } |
| + |
| + bool Next(); |
| + |
| + void Reset() { |
| + index_ = -1; |
| + ch_ = -1; |
| + } |
| + |
| + private: |
| + const uint16_t* utf16_array_; |
| + intptr_t array_len_; |
| + intptr_t index_; |
| + int32_t ch_; |
| + DISALLOW_IMPLICIT_CONSTRUCTORS(CodePointIterator); |
| + }; |
| + |
| // Returns the length of the code point in UTF-16 code units. |
| static intptr_t Length(int32_t ch) { |
| return (ch <= kMaxBmpCodepoint) ? 1 : 2; |