Chromium Code Reviews| Index: runtime/vm/unicode.h |
| diff --git a/runtime/vm/unicode.h b/runtime/vm/unicode.h |
| index 03a4b29d879898c2c83f06aac4a175d4729db209..d922ce4d430750dc5aeceb68e84a1597f522af1f 100644 |
| --- a/runtime/vm/unicode.h |
| +++ b/runtime/vm/unicode.h |
| @@ -1,4 +1,4 @@ |
| -// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| // for details. All rights reserved. Use of this source code is governed by a |
| // BSD-style license that can be found in the LICENSE file. |
| @@ -32,6 +32,11 @@ class Utf8 : AllStatic { |
| // Returns true if 'utf8_array' is a valid UTF-8 string. |
| static bool IsValid(const uint8_t* utf8_array, intptr_t array_len); |
| + // Returns true if 'utf8_array' is a valid UTF-8 string allowing |
| + // UTF-8 encoded UTF-16 surrogate code units. |
| + static bool IsValidAllowSurrogates( |
| + const uint8_t* utf8_array, intptr_t array_len); |
| + |
| static intptr_t Length(int32_t ch); |
| static intptr_t Length(const String& str); |
| @@ -41,6 +46,9 @@ class Utf8 : AllStatic { |
| static intptr_t Decode(const uint8_t* utf8_array, |
| intptr_t array_len, |
| int32_t* ch); |
| + static intptr_t DecodeAllowSurrogates(const uint8_t* utf8_array, |
| + intptr_t array_len, |
| + int32_t* ch); |
| static bool DecodeToLatin1(const uint8_t* utf8_array, |
| intptr_t array_len, |
| @@ -50,6 +58,10 @@ class Utf8 : AllStatic { |
| intptr_t array_len, |
| uint16_t* dst, |
| intptr_t len); |
| + static bool DecodeToUTF16AllowSurrogates(const uint8_t* utf8_array, |
| + intptr_t array_len, |
| + uint16_t* dst, |
| + intptr_t len); |
| static bool DecodeToUTF32(const uint8_t* utf8_array, |
| intptr_t array_len, |
| int32_t* dst, |
| @@ -73,6 +85,31 @@ class Utf16 : AllStatic { |
| static const int32_t kSurrogateOffset = (0x10000 - (0xD800 << 10) - 0xDC00); |
| + class CodePointIterator { |
| + public: |
| + explicit CodePointIterator(const uint16_t* utf16_array, |
| + intptr_t array_len) |
|
siva
2012/11/27 03:00:25
Has two parameters in the constructor why is expli
Søren Gjesse
2012/11/27 11:35:54
Not needed - removed.
|
| + : utf16_array_(utf16_array), |
| + array_len_(array_len), |
| + index_(-1), |
| + ch_(-1) { |
| + } |
| + |
| + int32_t Current() { |
|
siva
2012/11/27 03:00:25
int32_t Current() const {
Søren Gjesse
2012/11/27 11:35:54
Done (added for String::CodePointIterator as well)
|
| + ASSERT(index_ >= 0); |
| + ASSERT(index_ < array_len_); |
| + return ch_; |
| + } |
| + |
| + bool Next(); |
| + |
| + private: |
| + const uint16_t* utf16_array_; |
| + intptr_t array_len_; |
| + intptr_t index_; |
| + int32_t ch_; |
|
siva
2012/11/27 03:00:25
Missing DISALLOW stuff?
Søren Gjesse
2012/11/27 11:35:54
Done.
|
| + }; |
| + |
| // Returns the length of the code point in UTF-16 code units. |
| static intptr_t Length(int32_t ch) { |
| return (ch <= kMaxBmpCodepoint) ? 1 : 2; |