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/object.h" | 5 #include "vm/object.h" |
6 | 6 |
7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
9 #include "vm/assembler.h" | 9 #include "vm/assembler.h" |
10 #include "vm/become.h" | 10 #include "vm/become.h" |
(...skipping 21191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
21202 result = OneByteString::New(length, space); | 21202 result = OneByteString::New(length, space); |
21203 } else { | 21203 } else { |
21204 result = TwoByteString::New(length, space); | 21204 result = TwoByteString::New(length, space); |
21205 } | 21205 } |
21206 String::Copy(result, 0, str, begin_index, length); | 21206 String::Copy(result, 0, str, begin_index, length); |
21207 return result.raw(); | 21207 return result.raw(); |
21208 } | 21208 } |
21209 | 21209 |
21210 | 21210 |
21211 const char* String::ToCString() const { | 21211 const char* String::ToCString() const { |
21212 if (IsOneByteString()) { | 21212 NoSafepointScope no_safepoint; |
21213 // Quick conversion if OneByteString contains only ASCII characters. | |
21214 intptr_t len = Length(); | |
21215 if (len == 0) { | |
21216 return ""; | |
21217 } | |
21218 Zone* zone = Thread::Current()->zone(); | |
21219 uint8_t* result = zone->Alloc<uint8_t>(len + 1); | |
21220 NoSafepointScope no_safepoint; | |
21221 const uint8_t* original_str = OneByteString::CharAddr(*this, 0); | |
21222 for (intptr_t i = 0; i < len; i++) { | |
21223 if (original_str[i] <= Utf8::kMaxOneByteChar) { | |
21224 result[i] = original_str[i]; | |
21225 } else { | |
21226 len = -1; | |
21227 break; | |
21228 } | |
21229 } | |
21230 if (len > 0) { | |
21231 result[len] = 0; | |
21232 return reinterpret_cast<const char*>(result); | |
21233 } | |
21234 } | |
21235 const intptr_t len = Utf8::Length(*this); | 21213 const intptr_t len = Utf8::Length(*this); |
21236 Zone* zone = Thread::Current()->zone(); | 21214 Zone* zone = Thread::Current()->zone(); |
21237 uint8_t* result = zone->Alloc<uint8_t>(len + 1); | 21215 uint8_t* result = zone->Alloc<uint8_t>(len + 1); |
21238 ToUTF8(result, len); | 21216 ToUTF8(result, len); |
21239 result[len] = 0; | 21217 result[len] = 0; |
21240 return reinterpret_cast<const char*>(result); | 21218 return reinterpret_cast<const char*>(result); |
21241 } | 21219 } |
21242 | 21220 |
21243 | 21221 |
21244 void String::ToUTF8(uint8_t* utf8_array, intptr_t array_len) const { | 21222 void String::ToUTF8(uint8_t* utf8_array, intptr_t array_len) const { |
(...skipping 2391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
23636 return UserTag::null(); | 23614 return UserTag::null(); |
23637 } | 23615 } |
23638 | 23616 |
23639 | 23617 |
23640 const char* UserTag::ToCString() const { | 23618 const char* UserTag::ToCString() const { |
23641 const String& tag_label = String::Handle(label()); | 23619 const String& tag_label = String::Handle(label()); |
23642 return tag_label.ToCString(); | 23620 return tag_label.ToCString(); |
23643 } | 23621 } |
23644 | 23622 |
23645 } // namespace dart | 23623 } // namespace dart |
OLD | NEW |