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

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

Issue 2081433002: Use official JSON encoding for stream (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Fixed & Added UTF-32 characters tests Created 4 years, 5 months 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
« no previous file with comments | « runtime/vm/json_test.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, 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
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 110
111 111
112 class Utf16 : AllStatic { 112 class Utf16 : AllStatic {
113 public: 113 public:
114 // Returns the length of the code point in UTF-16 code units. 114 // Returns the length of the code point in UTF-16 code units.
115 static intptr_t Length(int32_t ch) { 115 static intptr_t Length(int32_t ch) {
116 return (ch <= Utf16::kMaxCodeUnit) ? 1 : 2; 116 return (ch <= Utf16::kMaxCodeUnit) ? 1 : 2;
117 } 117 }
118 118
119 // Returns true if ch is a lead or trail surrogate. 119 // Returns true if ch is a lead or trail surrogate.
120 static bool IsSurrogate(int32_t ch) { 120 static bool IsSurrogate(uint32_t ch) {
121 return (ch & 0xFFFFF800) == 0xD800; 121 return (ch & 0xFFFFF800) == 0xD800;
122 } 122 }
123 123
124 // Returns true if ch is a lead surrogate. 124 // Returns true if ch is a lead surrogate.
125 static bool IsLeadSurrogate(int32_t ch) { 125 static bool IsLeadSurrogate(uint32_t ch) {
126 return (ch & 0xFFFFFC00) == 0xD800; 126 return (ch & 0xFFFFFC00) == 0xD800;
127 } 127 }
128 128
129 // Returns true if ch is a low surrogate. 129 // Returns true if ch is a low surrogate.
130 static bool IsTrailSurrogate(int32_t ch) { 130 static bool IsTrailSurrogate(uint32_t ch) {
131 return (ch & 0xFFFFFC00) == 0xDC00; 131 return (ch & 0xFFFFFC00) == 0xDC00;
132 } 132 }
133 133
134 // Returns the character at i and advances i to the next character 134 // Returns the character at i and advances i to the next character
135 // boundary. 135 // boundary.
136 static int32_t Next(const uint16_t* characters, intptr_t* i, intptr_t len) { 136 static int32_t Next(const uint16_t* characters, intptr_t* i, intptr_t len) {
137 int32_t ch = characters[*i]; 137 int32_t ch = characters[*i];
138 if (Utf16::IsLeadSurrogate(ch) && (*i < (len - 1))) { 138 if (Utf16::IsLeadSurrogate(ch) && (*i < (len - 1))) {
139 int32_t ch2 = characters[*i + 1]; 139 int32_t ch2 = characters[*i + 1];
140 if (Utf16::IsTrailSurrogate(ch2)) { 140 if (Utf16::IsTrailSurrogate(ch2)) {
141 ch = Utf16::Decode(ch, ch2); 141 ch = Utf16::Decode(ch, ch2);
142 *i += 1; 142 *i += 1;
143 } 143 }
144 } 144 }
145 *i += 1; 145 *i += 1;
146 return ch; 146 return ch;
147 } 147 }
148 148
149 // Decodes a surrogate pair into a supplementary code point. 149 // Decodes a surrogate pair into a supplementary code point.
150 static int32_t Decode(int32_t lead, int32_t trail) { 150 static int32_t Decode(uint16_t lead, uint16_t trail) {
151 return 0x10000 + ((lead & 0x3FF) << 10) + (trail & 0x3FF); 151 return 0x10000 + ((lead & 0x000003FF) << 10) + (trail & 0x3FF);
152 } 152 }
153 153
154 // Encodes a single code point. 154 // Encodes a single code point.
155 static void Encode(int32_t codepoint, uint16_t* dst); 155 static void Encode(int32_t codepoint, uint16_t* dst);
156 156
157 static const int32_t kMaxCodeUnit = 0xFFFF; 157 static const int32_t kMaxCodeUnit = 0xFFFF;
158 158
159 private: 159 private:
160 static const int32_t kLeadSurrogateOffset = (0xD800 - (0x10000 >> 10)); 160 static const int32_t kLeadSurrogateOffset = (0xD800 - (0x10000 >> 10));
161 161
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 // Data for small code points with one mapping 222 // Data for small code points with one mapping
223 static const int16_t stage2_[]; 223 static const int16_t stage2_[];
224 224
225 // Data for large code points or code points with both mappings. 225 // Data for large code points or code points with both mappings.
226 static const int32_t stage2_exception_[][2]; 226 static const int32_t stage2_exception_[][2];
227 }; 227 };
228 228
229 } // namespace dart 229 } // namespace dart
230 230
231 #endif // VM_UNICODE_H_ 231 #endif // VM_UNICODE_H_
OLDNEW
« no previous file with comments | « runtime/vm/json_test.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698