Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 |
| 11 namespace dart { | 11 namespace dart { |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 25 static const intptr_t kMaxThreeByteChar = 0xFFFF; | 25 static const intptr_t kMaxThreeByteChar = 0xFFFF; |
| 26 static const intptr_t kMaxFourByteChar = 0x10FFFF; | 26 static const intptr_t kMaxFourByteChar = 0x10FFFF; |
| 27 | 27 |
| 28 static intptr_t CodePointCount(const uint8_t* utf8_array, | 28 static intptr_t CodePointCount(const uint8_t* utf8_array, |
| 29 intptr_t array_len, | 29 intptr_t array_len, |
| 30 Type* type); | 30 Type* type); |
| 31 | 31 |
| 32 // Returns true if 'utf8_array' is a valid UTF-8 string. | 32 // Returns true if 'utf8_array' is a valid UTF-8 string. |
| 33 static bool IsValid(const uint8_t* utf8_array, intptr_t array_len); | 33 static bool IsValid(const uint8_t* utf8_array, intptr_t array_len); |
| 34 | 34 |
| 35 // Returns true if 'utf8_array' is a valid UTF-8 string allowing | |
| 36 // UTF-8 encoded UTF-16 surrogate code units. | |
| 37 static bool IsValidAllowSurrogates( | |
| 38 const uint8_t* utf8_array, intptr_t array_len); | |
| 39 | |
| 35 static intptr_t Length(int32_t ch); | 40 static intptr_t Length(int32_t ch); |
| 36 static intptr_t Length(const String& str); | 41 static intptr_t Length(const String& str); |
| 37 | 42 |
| 38 static intptr_t Encode(int32_t ch, char* dst); | 43 static intptr_t Encode(int32_t ch, char* dst); |
| 39 static intptr_t Encode(const String& src, char* dst, intptr_t len); | 44 static intptr_t Encode(const String& src, char* dst, intptr_t len); |
| 40 | 45 |
| 41 static intptr_t Decode(const uint8_t* utf8_array, | 46 static intptr_t Decode(const uint8_t* utf8_array, |
| 42 intptr_t array_len, | 47 intptr_t array_len, |
| 43 int32_t* ch); | 48 int32_t* ch); |
| 49 static intptr_t DecodeAllowSurrogates(const uint8_t* utf8_array, | |
| 50 intptr_t array_len, | |
| 51 int32_t* ch); | |
| 44 | 52 |
| 45 static bool DecodeToLatin1(const uint8_t* utf8_array, | 53 static bool DecodeToLatin1(const uint8_t* utf8_array, |
| 46 intptr_t array_len, | 54 intptr_t array_len, |
| 47 uint8_t* dst, | 55 uint8_t* dst, |
| 48 intptr_t len); | 56 intptr_t len); |
| 49 static bool DecodeToUTF16(const uint8_t* utf8_array, | 57 static bool DecodeToUTF16(const uint8_t* utf8_array, |
| 50 intptr_t array_len, | 58 intptr_t array_len, |
| 51 uint16_t* dst, | 59 uint16_t* dst, |
| 52 intptr_t len); | 60 intptr_t len); |
| 61 static bool DecodeToUTF16AllowSurrogates(const uint8_t* utf8_array, | |
| 62 intptr_t array_len, | |
| 63 uint16_t* dst, | |
| 64 intptr_t len); | |
| 53 static bool DecodeToUTF32(const uint8_t* utf8_array, | 65 static bool DecodeToUTF32(const uint8_t* utf8_array, |
| 54 intptr_t array_len, | 66 intptr_t array_len, |
| 55 int32_t* dst, | 67 int32_t* dst, |
| 56 intptr_t len); | 68 intptr_t len); |
| 57 static bool DecodeCStringToUTF32(const char* str, | 69 static bool DecodeCStringToUTF32(const char* str, |
| 58 int32_t* dst, | 70 int32_t* dst, |
| 59 intptr_t len) { | 71 intptr_t len) { |
| 60 ASSERT(str != NULL); | 72 ASSERT(str != NULL); |
| 61 intptr_t array_len = strlen(str); | 73 intptr_t array_len = strlen(str); |
| 62 const uint8_t* utf8_array = reinterpret_cast<const uint8_t*>(str); | 74 const uint8_t* utf8_array = reinterpret_cast<const uint8_t*>(str); |
| 63 return DecodeToUTF32(utf8_array, array_len, dst, len); | 75 return DecodeToUTF32(utf8_array, array_len, dst, len); |
| 64 } | 76 } |
| 65 }; | 77 }; |
| 66 | 78 |
| 67 | 79 |
| 68 class Utf16 : AllStatic { | 80 class Utf16 : AllStatic { |
| 69 public: | 81 public: |
| 70 static const int32_t kMaxBmpCodepoint = 0xFFFF; | 82 static const int32_t kMaxBmpCodepoint = 0xFFFF; |
| 71 | 83 |
| 72 static const int32_t kLeadSurrogateOffset = (0xD800 - (0x10000 >> 10)); | 84 static const int32_t kLeadSurrogateOffset = (0xD800 - (0x10000 >> 10)); |
| 73 | 85 |
| 74 static const int32_t kSurrogateOffset = (0x10000 - (0xD800 << 10) - 0xDC00); | 86 static const int32_t kSurrogateOffset = (0x10000 - (0xD800 << 10) - 0xDC00); |
| 75 | 87 |
| 88 class CodePointIterator { | |
| 89 public: | |
| 90 explicit CodePointIterator(const uint16_t* utf16_array, | |
| 91 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.
| |
| 92 : utf16_array_(utf16_array), | |
| 93 array_len_(array_len), | |
| 94 index_(-1), | |
| 95 ch_(-1) { | |
| 96 } | |
| 97 | |
| 98 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)
| |
| 99 ASSERT(index_ >= 0); | |
| 100 ASSERT(index_ < array_len_); | |
| 101 return ch_; | |
| 102 } | |
| 103 | |
| 104 bool Next(); | |
| 105 | |
| 106 private: | |
| 107 const uint16_t* utf16_array_; | |
| 108 intptr_t array_len_; | |
| 109 intptr_t index_; | |
| 110 int32_t ch_; | |
|
siva
2012/11/27 03:00:25
Missing DISALLOW stuff?
Søren Gjesse
2012/11/27 11:35:54
Done.
| |
| 111 }; | |
| 112 | |
| 76 // Returns the length of the code point in UTF-16 code units. | 113 // Returns the length of the code point in UTF-16 code units. |
| 77 static intptr_t Length(int32_t ch) { | 114 static intptr_t Length(int32_t ch) { |
| 78 return (ch <= kMaxBmpCodepoint) ? 1 : 2; | 115 return (ch <= kMaxBmpCodepoint) ? 1 : 2; |
| 79 } | 116 } |
| 80 | 117 |
| 81 // Returns true if ch is a lead or trail surrogate. | 118 // Returns true if ch is a lead or trail surrogate. |
| 82 static bool IsSurrogate(int32_t ch) { | 119 static bool IsSurrogate(int32_t ch) { |
| 83 return (ch & 0xFFFFF800) == 0xD800; | 120 return (ch & 0xFFFFF800) == 0xD800; |
| 84 } | 121 } |
| 85 | 122 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 162 // Data for small code points with one mapping | 199 // Data for small code points with one mapping |
| 163 static const int16_t stage2_[]; | 200 static const int16_t stage2_[]; |
| 164 | 201 |
| 165 // Data for large code points or code points with both mappings. | 202 // Data for large code points or code points with both mappings. |
| 166 static const int32_t stage2_exception_[][2]; | 203 static const int32_t stage2_exception_[][2]; |
| 167 }; | 204 }; |
| 168 | 205 |
| 169 } // namespace dart | 206 } // namespace dart |
| 170 | 207 |
| 171 #endif // VM_UNICODE_H_ | 208 #endif // VM_UNICODE_H_ |
| OLD | NEW |