| 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/bigint_operations.h" | 10 #include "vm/bigint_operations.h" |
| (...skipping 10069 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10080 TwoByteString::CharAddr(strobj, 0), len); | 10080 TwoByteString::CharAddr(strobj, 0), len); |
| 10081 return strobj.raw(); | 10081 return strobj.raw(); |
| 10082 } | 10082 } |
| 10083 | 10083 |
| 10084 | 10084 |
| 10085 RawString* String::New(const uint16_t* utf16_array, | 10085 RawString* String::New(const uint16_t* utf16_array, |
| 10086 intptr_t array_len, | 10086 intptr_t array_len, |
| 10087 Heap::Space space) { | 10087 Heap::Space space) { |
| 10088 bool is_one_byte_string = true; | 10088 bool is_one_byte_string = true; |
| 10089 for (intptr_t i = 0; i < array_len; ++i) { | 10089 for (intptr_t i = 0; i < array_len; ++i) { |
| 10090 if (utf16_array[i] > 0xFF) { | 10090 if (!Utf::IsLatin1(utf16_array[i])) { |
| 10091 is_one_byte_string = false; | 10091 is_one_byte_string = false; |
| 10092 break; | 10092 break; |
| 10093 } | 10093 } |
| 10094 } | 10094 } |
| 10095 if (is_one_byte_string) { | 10095 if (is_one_byte_string) { |
| 10096 return OneByteString::New(utf16_array, array_len, space); | 10096 return OneByteString::New(utf16_array, array_len, space); |
| 10097 } | 10097 } |
| 10098 return TwoByteString::New(utf16_array, array_len, space); | 10098 return TwoByteString::New(utf16_array, array_len, space); |
| 10099 } | 10099 } |
| 10100 | 10100 |
| 10101 | 10101 |
| 10102 RawString* String::New(const int32_t* utf32_array, | 10102 RawString* String::New(const int32_t* utf32_array, |
| 10103 intptr_t array_len, | 10103 intptr_t array_len, |
| 10104 Heap::Space space) { | 10104 Heap::Space space) { |
| 10105 bool is_one_byte_string = true; | 10105 bool is_one_byte_string = true; |
| 10106 intptr_t utf16_len = array_len; | 10106 intptr_t utf16_len = array_len; |
| 10107 for (intptr_t i = 0; i < array_len; ++i) { | 10107 for (intptr_t i = 0; i < array_len; ++i) { |
| 10108 if (utf32_array[i] > 0xFF) { | 10108 if (!Utf::IsLatin1(utf32_array[i])) { |
| 10109 is_one_byte_string = false; | 10109 is_one_byte_string = false; |
| 10110 } | 10110 if (Utf::IsSupplementary(utf32_array[i])) { |
| 10111 if (utf32_array[i] > 0xFFFF) { | 10111 utf16_len += 1; |
| 10112 utf16_len += 1; | 10112 } |
| 10113 } | 10113 } |
| 10114 } | 10114 } |
| 10115 if (is_one_byte_string) { | 10115 if (is_one_byte_string) { |
| 10116 return OneByteString::New(utf32_array, array_len, space); | 10116 return OneByteString::New(utf32_array, array_len, space); |
| 10117 } | 10117 } |
| 10118 return TwoByteString::New(utf16_len, utf32_array, array_len, space); | 10118 return TwoByteString::New(utf16_len, utf32_array, array_len, space); |
| 10119 } | 10119 } |
| 10120 | 10120 |
| 10121 | 10121 |
| 10122 RawString* String::New(const String& str, Heap::Space space) { | 10122 RawString* String::New(const String& str, Heap::Space space) { |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10179 | 10179 |
| 10180 void String::Copy(const String& dst, intptr_t dst_offset, | 10180 void String::Copy(const String& dst, intptr_t dst_offset, |
| 10181 const uint16_t* utf16_array, | 10181 const uint16_t* utf16_array, |
| 10182 intptr_t array_len) { | 10182 intptr_t array_len) { |
| 10183 ASSERT(dst_offset >= 0); | 10183 ASSERT(dst_offset >= 0); |
| 10184 ASSERT(array_len >= 0); | 10184 ASSERT(array_len >= 0); |
| 10185 ASSERT(array_len <= (dst.Length() - dst_offset)); | 10185 ASSERT(array_len <= (dst.Length() - dst_offset)); |
| 10186 if (dst.IsOneByteString()) { | 10186 if (dst.IsOneByteString()) { |
| 10187 NoGCScope no_gc; | 10187 NoGCScope no_gc; |
| 10188 for (intptr_t i = 0; i < array_len; ++i) { | 10188 for (intptr_t i = 0; i < array_len; ++i) { |
| 10189 ASSERT(utf16_array[i] <= 0xFF); | 10189 ASSERT(Utf::IsLatin1(utf16_array[i])); |
| 10190 *OneByteString::CharAddr(dst, i + dst_offset) = utf16_array[i]; | 10190 *OneByteString::CharAddr(dst, i + dst_offset) = utf16_array[i]; |
| 10191 } | 10191 } |
| 10192 } else { | 10192 } else { |
| 10193 ASSERT(dst.IsTwoByteString()); | 10193 ASSERT(dst.IsTwoByteString()); |
| 10194 NoGCScope no_gc; | 10194 NoGCScope no_gc; |
| 10195 if (array_len > 0) { | 10195 if (array_len > 0) { |
| 10196 memmove(TwoByteString::CharAddr(dst, dst_offset), | 10196 memmove(TwoByteString::CharAddr(dst, dst_offset), |
| 10197 utf16_array, | 10197 utf16_array, |
| 10198 array_len * 2); | 10198 array_len * 2); |
| 10199 } | 10199 } |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10334 return Symbols::Empty(); | 10334 return Symbols::Empty(); |
| 10335 } | 10335 } |
| 10336 if (begin_index > str.Length()) { | 10336 if (begin_index > str.Length()) { |
| 10337 return String::null(); | 10337 return String::null(); |
| 10338 } | 10338 } |
| 10339 String& result = String::Handle(); | 10339 String& result = String::Handle(); |
| 10340 bool is_one_byte_string = true; | 10340 bool is_one_byte_string = true; |
| 10341 intptr_t char_size = str.CharSize(); | 10341 intptr_t char_size = str.CharSize(); |
| 10342 if (char_size == kTwoByteChar) { | 10342 if (char_size == kTwoByteChar) { |
| 10343 for (intptr_t i = begin_index; i < begin_index + length; ++i) { | 10343 for (intptr_t i = begin_index; i < begin_index + length; ++i) { |
| 10344 if (str.CharAt(i) > 0xFF) { | 10344 if (!Utf::IsLatin1(str.CharAt(i))) { |
| 10345 is_one_byte_string = false; | 10345 is_one_byte_string = false; |
| 10346 break; | 10346 break; |
| 10347 } | 10347 } |
| 10348 } | 10348 } |
| 10349 } | 10349 } |
| 10350 if (is_one_byte_string) { | 10350 if (is_one_byte_string) { |
| 10351 result ^= OneByteString::New(length, space); | 10351 result ^= OneByteString::New(length, space); |
| 10352 } else { | 10352 } else { |
| 10353 result ^= TwoByteString::New(length, space); | 10353 result ^= TwoByteString::New(length, space); |
| 10354 } | 10354 } |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10470 int32_t src = it.Current(); | 10470 int32_t src = it.Current(); |
| 10471 int32_t dst = mapping(src); | 10471 int32_t dst = mapping(src); |
| 10472 if (src != dst) { | 10472 if (src != dst) { |
| 10473 has_mapping = true; | 10473 has_mapping = true; |
| 10474 } | 10474 } |
| 10475 dst_max = Utils::Maximum(dst_max, dst); | 10475 dst_max = Utils::Maximum(dst_max, dst); |
| 10476 } | 10476 } |
| 10477 if (!has_mapping) { | 10477 if (!has_mapping) { |
| 10478 return str.raw(); | 10478 return str.raw(); |
| 10479 } | 10479 } |
| 10480 if (dst_max <= 0xFF) { | 10480 if (Utf::IsLatin1(dst_max)) { |
| 10481 return OneByteString::Transform(mapping, str, space); | 10481 return OneByteString::Transform(mapping, str, space); |
| 10482 } | 10482 } |
| 10483 ASSERT(dst_max > 0xFF); | 10483 ASSERT(Utf::IsBmp(dst_max) || Utf::IsSupplementary(dst_max)); |
| 10484 return TwoByteString::Transform(mapping, str, space); | 10484 return TwoByteString::Transform(mapping, str, space); |
| 10485 } | 10485 } |
| 10486 | 10486 |
| 10487 | 10487 |
| 10488 RawString* String::ToUpperCase(const String& str, Heap::Space space) { | 10488 RawString* String::ToUpperCase(const String& str, Heap::Space space) { |
| 10489 // TODO(cshapiro): create a fast-path for OneByteString instances. | 10489 // TODO(cshapiro): create a fast-path for OneByteString instances. |
| 10490 return Transform(CaseMapping::ToUpper, str, space); | 10490 return Transform(CaseMapping::ToUpper, str, space); |
| 10491 } | 10491 } |
| 10492 | 10492 |
| 10493 | 10493 |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10640 } | 10640 } |
| 10641 return OneByteString::raw(result); | 10641 return OneByteString::raw(result); |
| 10642 } | 10642 } |
| 10643 | 10643 |
| 10644 | 10644 |
| 10645 RawOneByteString* OneByteString::New(const uint16_t* characters, | 10645 RawOneByteString* OneByteString::New(const uint16_t* characters, |
| 10646 intptr_t len, | 10646 intptr_t len, |
| 10647 Heap::Space space) { | 10647 Heap::Space space) { |
| 10648 const String& result =String::Handle(OneByteString::New(len, space)); | 10648 const String& result =String::Handle(OneByteString::New(len, space)); |
| 10649 for (intptr_t i = 0; i < len; ++i) { | 10649 for (intptr_t i = 0; i < len; ++i) { |
| 10650 ASSERT(characters[i] <= 0xFF); | 10650 ASSERT(Utf::IsLatin1(characters[i])); |
| 10651 *CharAddr(result, i) = characters[i]; | 10651 *CharAddr(result, i) = characters[i]; |
| 10652 } | 10652 } |
| 10653 return OneByteString::raw(result); | 10653 return OneByteString::raw(result); |
| 10654 } | 10654 } |
| 10655 | 10655 |
| 10656 | 10656 |
| 10657 RawOneByteString* OneByteString::New(const int32_t* characters, | 10657 RawOneByteString* OneByteString::New(const int32_t* characters, |
| 10658 intptr_t len, | 10658 intptr_t len, |
| 10659 Heap::Space space) { | 10659 Heap::Space space) { |
| 10660 const String& result = String::Handle(OneByteString::New(len, space)); | 10660 const String& result = String::Handle(OneByteString::New(len, space)); |
| 10661 for (intptr_t i = 0; i < len; ++i) { | 10661 for (intptr_t i = 0; i < len; ++i) { |
| 10662 ASSERT(characters[i] <= 0xFF); | 10662 ASSERT(Utf::IsLatin1(characters[i])); |
| 10663 *CharAddr(result, i) = characters[i]; | 10663 *CharAddr(result, i) = characters[i]; |
| 10664 } | 10664 } |
| 10665 return OneByteString::raw(result); | 10665 return OneByteString::raw(result); |
| 10666 } | 10666 } |
| 10667 | 10667 |
| 10668 | 10668 |
| 10669 RawOneByteString* OneByteString::New(const String& str, | 10669 RawOneByteString* OneByteString::New(const String& str, |
| 10670 Heap::Space space) { | 10670 Heap::Space space) { |
| 10671 intptr_t len = str.Length(); | 10671 intptr_t len = str.Length(); |
| 10672 const String& result = String::Handle(OneByteString::New(len, space)); | 10672 const String& result = String::Handle(OneByteString::New(len, space)); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10722 | 10722 |
| 10723 | 10723 |
| 10724 RawOneByteString* OneByteString::Transform(int32_t (*mapping)(int32_t ch), | 10724 RawOneByteString* OneByteString::Transform(int32_t (*mapping)(int32_t ch), |
| 10725 const String& str, | 10725 const String& str, |
| 10726 Heap::Space space) { | 10726 Heap::Space space) { |
| 10727 ASSERT(!str.IsNull()); | 10727 ASSERT(!str.IsNull()); |
| 10728 intptr_t len = str.Length(); | 10728 intptr_t len = str.Length(); |
| 10729 const String& result = String::Handle(OneByteString::New(len, space)); | 10729 const String& result = String::Handle(OneByteString::New(len, space)); |
| 10730 for (intptr_t i = 0; i < len; ++i) { | 10730 for (intptr_t i = 0; i < len; ++i) { |
| 10731 int32_t ch = mapping(str.CharAt(i)); | 10731 int32_t ch = mapping(str.CharAt(i)); |
| 10732 ASSERT(ch >= 0 && ch <= 0xFF); | 10732 ASSERT(Utf::IsLatin1(ch)); |
| 10733 *CharAddr(result, i) = ch; | 10733 *CharAddr(result, i) = ch; |
| 10734 } | 10734 } |
| 10735 return OneByteString::raw(result); | 10735 return OneByteString::raw(result); |
| 10736 } | 10736 } |
| 10737 | 10737 |
| 10738 | 10738 |
| 10739 RawTwoByteString* TwoByteString::EscapeSpecialCharacters(const String& str, | 10739 RawTwoByteString* TwoByteString::EscapeSpecialCharacters(const String& str, |
| 10740 bool raw_str) { | 10740 bool raw_str) { |
| 10741 intptr_t len = str.Length(); | 10741 intptr_t len = str.Length(); |
| 10742 if (len > 0) { | 10742 if (len > 0) { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10807 RawTwoByteString* TwoByteString::New(intptr_t utf16_len, | 10807 RawTwoByteString* TwoByteString::New(intptr_t utf16_len, |
| 10808 const int32_t* utf32_array, | 10808 const int32_t* utf32_array, |
| 10809 intptr_t array_len, | 10809 intptr_t array_len, |
| 10810 Heap::Space space) { | 10810 Heap::Space space) { |
| 10811 ASSERT((array_len > 0) && (utf16_len >= array_len)); | 10811 ASSERT((array_len > 0) && (utf16_len >= array_len)); |
| 10812 const String& result = String::Handle(TwoByteString::New(utf16_len, space)); | 10812 const String& result = String::Handle(TwoByteString::New(utf16_len, space)); |
| 10813 { | 10813 { |
| 10814 NoGCScope no_gc; | 10814 NoGCScope no_gc; |
| 10815 intptr_t j = 0; | 10815 intptr_t j = 0; |
| 10816 for (intptr_t i = 0; i < array_len; ++i) { | 10816 for (intptr_t i = 0; i < array_len; ++i) { |
| 10817 if (utf32_array[i] > 0xffff) { | 10817 if (Utf::IsSupplementary(utf32_array[i])) { |
| 10818 ASSERT(j < (utf16_len - 1)); | 10818 ASSERT(j < (utf16_len - 1)); |
| 10819 Utf16::Encode(utf32_array[i], CharAddr(result, j)); | 10819 Utf16::Encode(utf32_array[i], CharAddr(result, j)); |
| 10820 j += 2; | 10820 j += 2; |
| 10821 } else { | 10821 } else { |
| 10822 ASSERT(j < utf16_len); | 10822 ASSERT(j < utf16_len); |
| 10823 *CharAddr(result, j) = utf32_array[i]; | 10823 *CharAddr(result, j) = utf32_array[i]; |
| 10824 j += 1; | 10824 j += 1; |
| 10825 } | 10825 } |
| 10826 } | 10826 } |
| 10827 } | 10827 } |
| (...skipping 1255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12083 } | 12083 } |
| 12084 return result.raw(); | 12084 return result.raw(); |
| 12085 } | 12085 } |
| 12086 | 12086 |
| 12087 | 12087 |
| 12088 const char* WeakProperty::ToCString() const { | 12088 const char* WeakProperty::ToCString() const { |
| 12089 return "_WeakProperty"; | 12089 return "_WeakProperty"; |
| 12090 } | 12090 } |
| 12091 | 12091 |
| 12092 } // namespace dart | 12092 } // namespace dart |
| OLD | NEW |