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 |
11 namespace dart { | 11 namespace dart { |
12 | 12 |
13 class String; | 13 class String; |
14 | 14 |
15 class Utf8 : AllStatic { | 15 class Utf8 : AllStatic { |
16 public: | 16 public: |
17 enum Type { | |
18 kISOLatin1 = 0, // ISO Latin-1 character set. | |
cshapiro
2012/10/24 23:52:29
Any reason for the "= 0" here? Do we care about t
siva
2012/10/26 21:38:29
No just following general style we have used for e
| |
19 kBMP, // Basic Multilingual Plane. | |
20 kSMP, // Supplementary Multilingual Plane. | |
21 }; | |
22 | |
cshapiro
2012/10/24 23:52:29
Adding constants for kMaxCodePoint and kMaxBmpCode
siva
2012/10/26 21:38:29
Done.
| |
17 static const intptr_t kMaxOneByteChar = 0x7F; | 23 static const intptr_t kMaxOneByteChar = 0x7F; |
18 static const intptr_t kMaxTwoByteChar = 0x7FF; | 24 static const intptr_t kMaxTwoByteChar = 0x7FF; |
19 static const intptr_t kMaxThreeByteChar = 0xFFFF; | 25 static const intptr_t kMaxThreeByteChar = 0xFFFF; |
20 static const intptr_t kMaxFourByteChar = 0x10FFFF; | 26 static const intptr_t kMaxFourByteChar = 0x10FFFF; |
27 static const int32_t kLeadOffset = (0xD800 - (0x10000 >> 10)); | |
28 static const int32_t kSurrogateOffset = (0x10000 - (0xD800 << 10) - 0xDC00); | |
21 | 29 |
22 static intptr_t CodePointCount(const char* str, intptr_t* width); | 30 static void ConvertUTF32ToUTF16(int32_t codepoint, uint16_t* dst); |
31 static intptr_t CodePointCount(const uint8_t* utf8_array, | |
32 intptr_t array_len, | |
33 Type* type); | |
23 | 34 |
35 // Returns true if C string is a valid UTF-8 string. | |
cshapiro
2012/10/24 23:52:29
...true if src is a...
siva
2012/10/26 21:38:29
Done.
| |
24 static bool IsValid(const char* src); | 36 static bool IsValid(const char* src); |
25 | 37 |
26 static intptr_t Length(int32_t ch); | 38 static intptr_t Length(int32_t ch); |
27 static intptr_t Length(const String& str); | 39 static intptr_t Length(const String& str); |
28 | 40 |
29 static intptr_t Encode(int32_t ch, char* dst); | 41 static intptr_t Encode(int32_t ch, char* dst); |
30 static intptr_t Encode(const String& src, char* dst, intptr_t len); | 42 static intptr_t Encode(const String& src, char* dst, intptr_t len); |
31 | 43 |
32 static intptr_t Decode(const char*, int32_t* ch); | 44 static intptr_t Decode(const uint8_t* utf8_array, |
33 static bool Decode(const char* src, uint8_t* dst, intptr_t len); | 45 intptr_t array_len, |
34 static bool Decode(const char* src, uint16_t* dst, intptr_t len); | 46 int32_t* ch); |
35 static bool Decode(const char* src, uint32_t* dst, intptr_t len); | 47 |
48 static bool DecodeToISOLatin1(const uint8_t* utf8_array, | |
49 intptr_t array_len, | |
50 uint8_t* dst, | |
51 intptr_t len); | |
52 static bool DecodeToUTF16(const uint8_t* utf8_array, | |
53 intptr_t array_len, | |
54 uint16_t* dst, | |
55 intptr_t len); | |
56 static bool DecodeToUTF32(const uint8_t* utf8_array, | |
57 intptr_t array_len, | |
58 uint32_t* dst, | |
59 intptr_t len); | |
60 static bool DecodeCStringToUTF32(const char* str, | |
61 uint32_t* dst, | |
62 intptr_t len) { | |
63 ASSERT(str != NULL); | |
64 intptr_t array_len = strlen(str); | |
65 const uint8_t* utf8_array = reinterpret_cast<const uint8_t*>(str); | |
66 return DecodeToUTF32(utf8_array, array_len, dst, len); | |
67 } | |
36 }; | 68 }; |
37 | 69 |
38 | 70 |
39 class CaseMapping : AllStatic { | 71 class CaseMapping : AllStatic { |
40 public: | 72 public: |
41 // Maps a code point to uppercase. | 73 // Maps a code point to uppercase. |
42 static int32_t ToUpper(int32_t code_point) { | 74 static int32_t ToUpper(int32_t code_point) { |
43 return Convert(code_point, kUppercase); | 75 return Convert(code_point, kUppercase); |
44 } | 76 } |
45 | 77 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
95 // Data for small code points with one mapping | 127 // Data for small code points with one mapping |
96 static const int16_t stage2_[]; | 128 static const int16_t stage2_[]; |
97 | 129 |
98 // Data for large code points or code points with both mappings. | 130 // Data for large code points or code points with both mappings. |
99 static const int32_t stage2_exception_[][2]; | 131 static const int32_t stage2_exception_[][2]; |
100 }; | 132 }; |
101 | 133 |
102 } // namespace dart | 134 } // namespace dart |
103 | 135 |
104 #endif // VM_UNICODE_H_ | 136 #endif // VM_UNICODE_H_ |
OLD | NEW |