| 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/cpu.h" | 10 #include "vm/cpu.h" |
| (...skipping 13226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13237 } | 13237 } |
| 13238 } | 13238 } |
| 13239 } | 13239 } |
| 13240 } | 13240 } |
| 13241 | 13241 |
| 13242 | 13242 |
| 13243 RawString* String::EscapeSpecialCharacters(const String& str) { | 13243 RawString* String::EscapeSpecialCharacters(const String& str) { |
| 13244 if (str.IsOneByteString()) { | 13244 if (str.IsOneByteString()) { |
| 13245 return OneByteString::EscapeSpecialCharacters(str); | 13245 return OneByteString::EscapeSpecialCharacters(str); |
| 13246 } | 13246 } |
| 13247 ASSERT(str.IsTwoByteString()); | 13247 if (str.IsTwoByteString()) { |
| 13248 return TwoByteString::EscapeSpecialCharacters(str); | 13248 return TwoByteString::EscapeSpecialCharacters(str); |
| 13249 } |
| 13250 if (str.IsExternalOneByteString()) { |
| 13251 return ExternalOneByteString::EscapeSpecialCharacters(str); |
| 13252 } |
| 13253 ASSERT(str.IsExternalTwoByteString()); |
| 13254 // If EscapeSpecialCharacters is frequently called on external two byte |
| 13255 // strings, we should implement it directly on ExternalTwoByteString rather |
| 13256 // than first converting to a TwoByteString. |
| 13257 return TwoByteString::EscapeSpecialCharacters( |
| 13258 String::Handle(TwoByteString::New(str, Heap::kNew))); |
| 13249 } | 13259 } |
| 13250 | 13260 |
| 13251 | 13261 |
| 13252 RawString* String::NewFormatted(const char* format, ...) { | 13262 RawString* String::NewFormatted(const char* format, ...) { |
| 13253 va_list args; | 13263 va_list args; |
| 13254 va_start(args, format); | 13264 va_start(args, format); |
| 13255 RawString* result = NewFormattedV(format, args); | 13265 RawString* result = NewFormattedV(format, args); |
| 13256 NoGCScope no_gc; | 13266 NoGCScope no_gc; |
| 13257 va_end(args); | 13267 va_end(args); |
| 13258 return result; | 13268 return result; |
| (...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13643 } | 13653 } |
| 13644 index_ = end_; | 13654 index_ = end_; |
| 13645 return false; | 13655 return false; |
| 13646 } | 13656 } |
| 13647 | 13657 |
| 13648 | 13658 |
| 13649 RawOneByteString* OneByteString::EscapeSpecialCharacters(const String& str) { | 13659 RawOneByteString* OneByteString::EscapeSpecialCharacters(const String& str) { |
| 13650 intptr_t len = str.Length(); | 13660 intptr_t len = str.Length(); |
| 13651 if (len > 0) { | 13661 if (len > 0) { |
| 13652 intptr_t num_escapes = 0; | 13662 intptr_t num_escapes = 0; |
| 13653 intptr_t index = 0; | |
| 13654 for (intptr_t i = 0; i < len; i++) { | 13663 for (intptr_t i = 0; i < len; i++) { |
| 13655 if (IsSpecialCharacter(*CharAddr(str, i))) { | 13664 if (IsSpecialCharacter(*CharAddr(str, i))) { |
| 13656 num_escapes += 1; | 13665 num_escapes += 1; |
| 13657 } | 13666 } |
| 13658 } | 13667 } |
| 13659 const String& dststr = String::Handle( | 13668 const String& dststr = String::Handle( |
| 13660 OneByteString::New(len + num_escapes, Heap::kNew)); | 13669 OneByteString::New(len + num_escapes, Heap::kNew)); |
| 13670 intptr_t index = 0; |
| 13661 for (intptr_t i = 0; i < len; i++) { | 13671 for (intptr_t i = 0; i < len; i++) { |
| 13662 if (IsSpecialCharacter(*CharAddr(str, i))) { | 13672 if (IsSpecialCharacter(*CharAddr(str, i))) { |
| 13663 *(CharAddr(dststr, index)) = '\\'; | 13673 *(CharAddr(dststr, index)) = '\\'; |
| 13664 *(CharAddr(dststr, index + 1)) = SpecialCharacter(*CharAddr(str, i)); | 13674 *(CharAddr(dststr, index + 1)) = SpecialCharacter(*CharAddr(str, i)); |
| 13665 index += 2; | 13675 index += 2; |
| 13666 } else { | 13676 } else { |
| 13667 *(CharAddr(dststr, index)) = *CharAddr(str, i); | 13677 *(CharAddr(dststr, index)) = *CharAddr(str, i); |
| 13668 index += 1; | 13678 index += 1; |
| 13669 } | 13679 } |
| 13670 } | 13680 } |
| 13671 return OneByteString::raw(dststr); | 13681 return OneByteString::raw(dststr); |
| 13672 } | 13682 } |
| 13673 return OneByteString::null(); | 13683 return OneByteString::New(0, Heap::kNew); |
| 13684 } |
| 13685 |
| 13686 RawOneByteString* ExternalOneByteString::EscapeSpecialCharacters( |
| 13687 const String& str) { |
| 13688 intptr_t len = str.Length(); |
| 13689 if (len > 0) { |
| 13690 intptr_t num_escapes = 0; |
| 13691 for (intptr_t i = 0; i < len; i++) { |
| 13692 if (IsSpecialCharacter(*CharAddr(str, i))) { |
| 13693 num_escapes += 1; |
| 13694 } |
| 13695 } |
| 13696 const String& dststr = String::Handle( |
| 13697 OneByteString::New(len + num_escapes, Heap::kNew)); |
| 13698 intptr_t index = 0; |
| 13699 for (intptr_t i = 0; i < len; i++) { |
| 13700 if (IsSpecialCharacter(*CharAddr(str, i))) { |
| 13701 *(OneByteString::CharAddr(dststr, index)) = '\\'; |
| 13702 *(OneByteString::CharAddr(dststr, index + 1)) = |
| 13703 SpecialCharacter(*CharAddr(str, i)); |
| 13704 index += 2; |
| 13705 } else { |
| 13706 *(OneByteString::CharAddr(dststr, index)) = *CharAddr(str, i); |
| 13707 index += 1; |
| 13708 } |
| 13709 } |
| 13710 return OneByteString::raw(dststr); |
| 13711 } |
| 13712 return OneByteString::New(0, Heap::kNew); |
| 13674 } | 13713 } |
| 13675 | 13714 |
| 13676 | 13715 |
| 13677 RawOneByteString* OneByteString::New(intptr_t len, | 13716 RawOneByteString* OneByteString::New(intptr_t len, |
| 13678 Heap::Space space) { | 13717 Heap::Space space) { |
| 13679 ASSERT(Isolate::Current() == Dart::vm_isolate() || | 13718 ASSERT(Isolate::Current() == Dart::vm_isolate() || |
| 13680 Isolate::Current()->object_store()->one_byte_string_class() != | 13719 Isolate::Current()->object_store()->one_byte_string_class() != |
| 13681 Class::null()); | 13720 Class::null()); |
| 13682 if (len < 0 || len > kMaxElements) { | 13721 if (len < 0 || len > kMaxElements) { |
| 13683 // This should be caught before we reach here. | 13722 // This should be caught before we reach here. |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13840 void OneByteString::Finalize(Dart_WeakPersistentHandle handle, void* peer) { | 13879 void OneByteString::Finalize(Dart_WeakPersistentHandle handle, void* peer) { |
| 13841 delete reinterpret_cast<ExternalStringData<uint8_t>*>(peer); | 13880 delete reinterpret_cast<ExternalStringData<uint8_t>*>(peer); |
| 13842 DeleteWeakPersistentHandle(handle); | 13881 DeleteWeakPersistentHandle(handle); |
| 13843 } | 13882 } |
| 13844 | 13883 |
| 13845 | 13884 |
| 13846 RawTwoByteString* TwoByteString::EscapeSpecialCharacters(const String& str) { | 13885 RawTwoByteString* TwoByteString::EscapeSpecialCharacters(const String& str) { |
| 13847 intptr_t len = str.Length(); | 13886 intptr_t len = str.Length(); |
| 13848 if (len > 0) { | 13887 if (len > 0) { |
| 13849 intptr_t num_escapes = 0; | 13888 intptr_t num_escapes = 0; |
| 13850 intptr_t index = 0; | |
| 13851 for (intptr_t i = 0; i < len; i++) { | 13889 for (intptr_t i = 0; i < len; i++) { |
| 13852 if (IsSpecialCharacter(*CharAddr(str, i))) { | 13890 if (IsSpecialCharacter(*CharAddr(str, i))) { |
| 13853 num_escapes += 1; | 13891 num_escapes += 1; |
| 13854 } | 13892 } |
| 13855 } | 13893 } |
| 13856 const String& dststr = String::Handle( | 13894 const String& dststr = String::Handle( |
| 13857 TwoByteString::New(len + num_escapes, Heap::kNew)); | 13895 TwoByteString::New(len + num_escapes, Heap::kNew)); |
| 13896 intptr_t index = 0; |
| 13858 for (intptr_t i = 0; i < len; i++) { | 13897 for (intptr_t i = 0; i < len; i++) { |
| 13859 if (IsSpecialCharacter(*CharAddr(str, i))) { | 13898 if (IsSpecialCharacter(*CharAddr(str, i))) { |
| 13860 *(CharAddr(dststr, index)) = '\\'; | 13899 *(CharAddr(dststr, index)) = '\\'; |
| 13861 *(CharAddr(dststr, index + 1)) = SpecialCharacter(*CharAddr(str, i)); | 13900 *(CharAddr(dststr, index + 1)) = SpecialCharacter(*CharAddr(str, i)); |
| 13862 index += 2; | 13901 index += 2; |
| 13863 } else { | 13902 } else { |
| 13864 *(CharAddr(dststr, index)) = *CharAddr(str, i); | 13903 *(CharAddr(dststr, index)) = *CharAddr(str, i); |
| 13865 index += 1; | 13904 index += 1; |
| 13866 } | 13905 } |
| 13867 } | 13906 } |
| 13868 return TwoByteString::raw(dststr); | 13907 return TwoByteString::raw(dststr); |
| 13869 } | 13908 } |
| 13870 return TwoByteString::null(); | 13909 return TwoByteString::New(0, Heap::kNew); |
| 13871 } | 13910 } |
| 13872 | 13911 |
| 13873 | 13912 |
| 13874 RawTwoByteString* TwoByteString::New(intptr_t len, | 13913 RawTwoByteString* TwoByteString::New(intptr_t len, |
| 13875 Heap::Space space) { | 13914 Heap::Space space) { |
| 13876 ASSERT(Isolate::Current()->object_store()->two_byte_string_class()); | 13915 ASSERT(Isolate::Current()->object_store()->two_byte_string_class()); |
| 13877 if (len < 0 || len > kMaxElements) { | 13916 if (len < 0 || len > kMaxElements) { |
| 13878 // This should be caught before we reach here. | 13917 // This should be caught before we reach here. |
| 13879 FATAL1("Fatal error in TwoByteString::New: invalid len %" Pd "\n", len); | 13918 FATAL1("Fatal error in TwoByteString::New: invalid len %" Pd "\n", len); |
| 13880 } | 13919 } |
| (...skipping 1299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15180 return "_MirrorReference"; | 15219 return "_MirrorReference"; |
| 15181 } | 15220 } |
| 15182 | 15221 |
| 15183 | 15222 |
| 15184 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { | 15223 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { |
| 15185 JSONObject jsobj(stream); | 15224 JSONObject jsobj(stream); |
| 15186 } | 15225 } |
| 15187 | 15226 |
| 15188 | 15227 |
| 15189 } // namespace dart | 15228 } // namespace dart |
| OLD | NEW |