| 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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 String::CodePointIterator it(str); | 131 String::CodePointIterator it(str); |
| 132 while (it.Next()) { | 132 while (it.Next()) { |
| 133 int32_t ch = it.Current(); | 133 int32_t ch = it.Current(); |
| 134 length += Utf8::Length(ch); | 134 length += Utf8::Length(ch); |
| 135 } | 135 } |
| 136 return length; | 136 return length; |
| 137 } | 137 } |
| 138 | 138 |
| 139 | 139 |
| 140 intptr_t Utf8::Encode(int32_t ch, char* dst) { | 140 intptr_t Utf8::Encode(int32_t ch, char* dst) { |
| 141 ASSERT(!Utf16::IsSurrogate(ch)); | |
| 142 static const int kMask = ~(1 << 6); | 141 static const int kMask = ~(1 << 6); |
| 143 if (ch <= kMaxOneByteChar) { | 142 if (ch <= kMaxOneByteChar) { |
| 144 dst[0] = ch; | 143 dst[0] = ch; |
| 145 return 1; | 144 return 1; |
| 146 } | 145 } |
| 147 if (ch <= kMaxTwoByteChar) { | 146 if (ch <= kMaxTwoByteChar) { |
| 148 dst[0] = 0xC0 | (ch >> 6); | 147 dst[0] = 0xC0 | (ch >> 6); |
| 149 dst[1] = 0x80 | (ch & kMask); | 148 dst[1] = 0x80 | (ch & kMask); |
| 150 return 2; | 149 return 2; |
| 151 } | 150 } |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 | 295 |
| 297 | 296 |
| 298 void Utf16::Encode(int32_t codepoint, uint16_t* dst) { | 297 void Utf16::Encode(int32_t codepoint, uint16_t* dst) { |
| 299 ASSERT(codepoint > Utf16::kMaxCodeUnit); | 298 ASSERT(codepoint > Utf16::kMaxCodeUnit); |
| 300 ASSERT(dst != NULL); | 299 ASSERT(dst != NULL); |
| 301 dst[0] = (Utf16::kLeadSurrogateOffset + (codepoint >> 10)); | 300 dst[0] = (Utf16::kLeadSurrogateOffset + (codepoint >> 10)); |
| 302 dst[1] = (0xDC00 + (codepoint & 0x3FF)); | 301 dst[1] = (0xDC00 + (codepoint & 0x3FF)); |
| 303 } | 302 } |
| 304 | 303 |
| 305 } // namespace dart | 304 } // namespace dart |
| OLD | NEW |