Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(308)

Side by Side Diff: runtime/vm/unicode.h

Issue 11280150: Add support for surrogates when serializing and deserializing for native ports (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Use iterator reset Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 10 matching lines...) Expand all
22 22
23 static const intptr_t kMaxOneByteChar = 0x7F; 23 static const intptr_t kMaxOneByteChar = 0x7F;
24 static const intptr_t kMaxTwoByteChar = 0x7FF; 24 static const intptr_t kMaxTwoByteChar = 0x7FF;
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. UTF-8 encoded UTF-16
33 // surrogate code units are allowed.
33 static bool IsValid(const uint8_t* utf8_array, intptr_t array_len); 34 static bool IsValid(const uint8_t* utf8_array, intptr_t array_len);
34 35
35 static intptr_t Length(int32_t ch); 36 static intptr_t Length(int32_t ch);
36 static intptr_t Length(const String& str); 37 static intptr_t Length(const String& str);
37 38
38 static intptr_t Encode(int32_t ch, char* dst); 39 static intptr_t Encode(int32_t ch, char* dst);
39 static intptr_t Encode(const String& src, char* dst, intptr_t len); 40 static intptr_t Encode(const String& src, char* dst, intptr_t len);
40 41
41 static intptr_t Decode(const uint8_t* utf8_array, 42 static intptr_t Decode(const uint8_t* utf8_array,
42 intptr_t array_len, 43 intptr_t array_len,
43 int32_t* ch); 44 int32_t* ch);
44
45 static bool DecodeToLatin1(const uint8_t* utf8_array, 45 static bool DecodeToLatin1(const uint8_t* utf8_array,
46 intptr_t array_len, 46 intptr_t array_len,
47 uint8_t* dst, 47 uint8_t* dst,
48 intptr_t len); 48 intptr_t len);
49 static bool DecodeToUTF16(const uint8_t* utf8_array, 49 static bool DecodeToUTF16(const uint8_t* utf8_array,
50 intptr_t array_len, 50 intptr_t array_len,
51 uint16_t* dst, 51 uint16_t* dst,
52 intptr_t len); 52 intptr_t len);
53 static bool DecodeToUTF32(const uint8_t* utf8_array, 53 static bool DecodeToUTF32(const uint8_t* utf8_array,
54 intptr_t array_len, 54 intptr_t array_len,
(...skipping 11 matching lines...) Expand all
66 66
67 67
68 class Utf16 : AllStatic { 68 class Utf16 : AllStatic {
69 public: 69 public:
70 static const int32_t kMaxBmpCodepoint = 0xFFFF; 70 static const int32_t kMaxBmpCodepoint = 0xFFFF;
71 71
72 static const int32_t kLeadSurrogateOffset = (0xD800 - (0x10000 >> 10)); 72 static const int32_t kLeadSurrogateOffset = (0xD800 - (0x10000 >> 10));
73 73
74 static const int32_t kSurrogateOffset = (0x10000 - (0xD800 << 10) - 0xDC00); 74 static const int32_t kSurrogateOffset = (0x10000 - (0xD800 << 10) - 0xDC00);
75 75
76 class CodePointIterator {
77 public:
78 CodePointIterator(const uint16_t* utf16_array, intptr_t array_len)
79 : utf16_array_(utf16_array),
80 array_len_(array_len),
81 index_(-1),
82 ch_(-1) {
83 }
84
85 int32_t Current() const {
86 ASSERT(index_ >= 0);
87 ASSERT(index_ < array_len_);
88 return ch_;
89 }
90
91 bool Next();
92
93 void Reset() {
94 index_ = -1;
95 ch_ = -1;
96 }
97
98 private:
99 const uint16_t* utf16_array_;
100 intptr_t array_len_;
101 intptr_t index_;
102 int32_t ch_;
103 DISALLOW_IMPLICIT_CONSTRUCTORS(CodePointIterator);
104 };
105
76 // Returns the length of the code point in UTF-16 code units. 106 // Returns the length of the code point in UTF-16 code units.
77 static intptr_t Length(int32_t ch) { 107 static intptr_t Length(int32_t ch) {
78 return (ch <= kMaxBmpCodepoint) ? 1 : 2; 108 return (ch <= kMaxBmpCodepoint) ? 1 : 2;
79 } 109 }
80 110
81 // Returns true if ch is a lead or trail surrogate. 111 // Returns true if ch is a lead or trail surrogate.
82 static bool IsSurrogate(int32_t ch) { 112 static bool IsSurrogate(int32_t ch) {
83 return (ch & 0xFFFFF800) == 0xD800; 113 return (ch & 0xFFFFF800) == 0xD800;
84 } 114 }
85 115
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 // Data for small code points with one mapping 192 // Data for small code points with one mapping
163 static const int16_t stage2_[]; 193 static const int16_t stage2_[];
164 194
165 // Data for large code points or code points with both mappings. 195 // Data for large code points or code points with both mappings.
166 static const int32_t stage2_exception_[][2]; 196 static const int32_t stage2_exception_[][2];
167 }; 197 };
168 198
169 } // namespace dart 199 } // namespace dart
170 200
171 #endif // VM_UNICODE_H_ 201 #endif // VM_UNICODE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698