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); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 // Data for small code points with one mapping | 174 // Data for small code points with one mapping |
163 static const int16_t stage2_[]; | 175 static const int16_t stage2_[]; |
164 | 176 |
165 // Data for large code points or code points with both mappings. | 177 // Data for large code points or code points with both mappings. |
166 static const int32_t stage2_exception_[][2]; | 178 static const int32_t stage2_exception_[][2]; |
167 }; | 179 }; |
168 | 180 |
169 } // namespace dart | 181 } // namespace dart |
170 | 182 |
171 #endif // VM_UNICODE_H_ | 183 #endif // VM_UNICODE_H_ |
OLD | NEW |