Chromium Code Reviews| 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 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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::null(); |
| 13674 } | 13684 } |
| 13675 | 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 intptr_t index = 0; | |
|
hausner
2013/09/30 22:54:37
declare index just before the loop below where it'
Jacob
2013/09/30 23:53:28
Fixed that here and in the code this method was co
| |
| 13692 for (intptr_t i = 0; i < len; i++) { | |
| 13693 if (IsSpecialCharacter(*CharAddr(str, i))) { | |
| 13694 num_escapes += 1; | |
| 13695 } | |
| 13696 } | |
| 13697 const String& dststr = String::Handle( | |
| 13698 OneByteString::New(len + num_escapes, Heap::kNew)); | |
| 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::null(); | |
|
hausner
2013/09/30 22:54:37
It it correct to return null when the input string
Jacob
2013/09/30 23:53:28
That is what the existing code did but I agree it
| |
| 13713 } | |
| 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. |
| 13684 FATAL1("Fatal error in OneByteString::New: invalid len %" Pd "\n", len); | 13723 FATAL1("Fatal error in OneByteString::New: invalid len %" Pd "\n", len); |
| 13685 } | 13724 } |
| (...skipping 1494 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 |