| OLD | NEW |
| 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 Loading... |
| 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))) { |
| 106 return false; | 107 return false; |
| 107 } | 108 } |
| 108 } | 109 } |
| 109 i += j; | 110 i += j; |
| 110 } | 111 } |
| 111 return true; | 112 return true; |
| 112 } | 113 } |
| 113 | 114 |
| 114 | 115 |
| 115 intptr_t Utf8::Length(int32_t ch) { | 116 intptr_t Utf8::Length(int32_t ch) { |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 ch = (ch << 6) + code_unit; | 194 ch = (ch << 6) + code_unit; |
| 194 } else { | 195 } else { |
| 195 *dst = -1; | 196 *dst = -1; |
| 196 return 0; | 197 return 0; |
| 197 } | 198 } |
| 198 } | 199 } |
| 199 ch -= kMagicBits[num_trail_bytes]; | 200 ch -= kMagicBits[num_trail_bytes]; |
| 200 if (!((is_malformed == false) && | 201 if (!((is_malformed == false) && |
| 201 (i == num_trail_bytes) && | 202 (i == num_trail_bytes) && |
| 202 !Utf::IsOutOfRange(ch) && | 203 !Utf::IsOutOfRange(ch) && |
| 203 !IsNonShortestForm(ch, i))) { | 204 !IsNonShortestForm(ch, i) && |
| 205 !Utf16::IsSurrogate(ch))) { |
| 204 *dst = -1; | 206 *dst = -1; |
| 205 return 0; | 207 return 0; |
| 206 } | 208 } |
| 207 } | 209 } |
| 208 *dst = ch; | 210 *dst = ch; |
| 209 return i; | 211 return i; |
| 210 } | 212 } |
| 211 | 213 |
| 212 | 214 |
| 213 bool Utf8::DecodeToLatin1(const uint8_t* utf8_array, | 215 bool Utf8::DecodeToLatin1(const uint8_t* utf8_array, |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 | 295 |
| 294 | 296 |
| 295 void Utf16::Encode(int32_t codepoint, uint16_t* dst) { | 297 void Utf16::Encode(int32_t codepoint, uint16_t* dst) { |
| 296 ASSERT(codepoint > Utf16::kMaxCodeUnit); | 298 ASSERT(codepoint > Utf16::kMaxCodeUnit); |
| 297 ASSERT(dst != NULL); | 299 ASSERT(dst != NULL); |
| 298 dst[0] = (Utf16::kLeadSurrogateOffset + (codepoint >> 10)); | 300 dst[0] = (Utf16::kLeadSurrogateOffset + (codepoint >> 10)); |
| 299 dst[1] = (0xDC00 + (codepoint & 0x3FF)); | 301 dst[1] = (0xDC00 + (codepoint & 0x3FF)); |
| 300 } | 302 } |
| 301 | 303 |
| 302 } // namespace dart | 304 } // namespace dart |
| OLD | NEW |