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

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

Issue 1309373005: Allow individual unicode surrogate strings (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Also fix unicode tests Created 5 years, 3 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/dart_api_impl_test.cc ('k') | runtime/vm/unicode_test.cc » ('j') | 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 #include "vm/unicode.h" 5 #include "vm/unicode.h"
6 6
7 #include "vm/allocation.h" 7 #include "vm/allocation.h"
8 #include "vm/globals.h" 8 #include "vm/globals.h"
9 #include "vm/object.h" 9 #include "vm/object.h"
10 10
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 is_malformed |= !IsTrailByte(code_unit); 95 is_malformed |= !IsTrailByte(code_unit);
96 ch = (ch << 6) + code_unit; 96 ch = (ch << 6) + code_unit;
97 } else { 97 } else {
98 return false; 98 return false;
99 } 99 }
100 } 100 }
101 ch -= kMagicBits[num_trail_bytes]; 101 ch -= kMagicBits[num_trail_bytes];
102 if (!((is_malformed == false) && 102 if (!((is_malformed == false) &&
103 (j == num_trail_bytes) && 103 (j == num_trail_bytes) &&
104 !Utf::IsOutOfRange(ch) && 104 !Utf::IsOutOfRange(ch) &&
105 !IsNonShortestForm(ch, j) && 105 !IsNonShortestForm(ch, j))) {
106 !Utf16::IsSurrogate(ch))) {
107 return false; 106 return false;
108 } 107 }
109 } 108 }
110 i += j; 109 i += j;
111 } 110 }
112 return true; 111 return true;
113 } 112 }
114 113
115 114
116 intptr_t Utf8::Length(int32_t ch) { 115 intptr_t Utf8::Length(int32_t ch) {
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 ch = (ch << 6) + code_unit; 193 ch = (ch << 6) + code_unit;
195 } else { 194 } else {
196 *dst = -1; 195 *dst = -1;
197 return 0; 196 return 0;
198 } 197 }
199 } 198 }
200 ch -= kMagicBits[num_trail_bytes]; 199 ch -= kMagicBits[num_trail_bytes];
201 if (!((is_malformed == false) && 200 if (!((is_malformed == false) &&
202 (i == num_trail_bytes) && 201 (i == num_trail_bytes) &&
203 !Utf::IsOutOfRange(ch) && 202 !Utf::IsOutOfRange(ch) &&
204 !IsNonShortestForm(ch, i) && 203 !IsNonShortestForm(ch, i))) {
205 !Utf16::IsSurrogate(ch))) {
206 *dst = -1; 204 *dst = -1;
207 return 0; 205 return 0;
208 } 206 }
209 } 207 }
210 *dst = ch; 208 *dst = ch;
211 return i; 209 return i;
212 } 210 }
213 211
214 212
215 bool Utf8::DecodeToLatin1(const uint8_t* utf8_array, 213 bool Utf8::DecodeToLatin1(const uint8_t* utf8_array,
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 293
296 294
297 void Utf16::Encode(int32_t codepoint, uint16_t* dst) { 295 void Utf16::Encode(int32_t codepoint, uint16_t* dst) {
298 ASSERT(codepoint > Utf16::kMaxCodeUnit); 296 ASSERT(codepoint > Utf16::kMaxCodeUnit);
299 ASSERT(dst != NULL); 297 ASSERT(dst != NULL);
300 dst[0] = (Utf16::kLeadSurrogateOffset + (codepoint >> 10)); 298 dst[0] = (Utf16::kLeadSurrogateOffset + (codepoint >> 10));
301 dst[1] = (0xDC00 + (codepoint & 0x3FF)); 299 dst[1] = (0xDC00 + (codepoint & 0x3FF));
302 } 300 }
303 301
304 } // namespace dart 302 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/dart_api_impl_test.cc ('k') | runtime/vm/unicode_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698