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/bigint_operations.h" | 10 #include "vm/bigint_operations.h" |
| (...skipping 10017 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 10028 | 10028 |
| 10029 const String& other_string = String::Cast(other); | 10029 const String& other_string = String::Cast(other); |
| 10030 if (this->HasHash() && other_string.HasHash() && | 10030 if (this->HasHash() && other_string.HasHash() && |
| 10031 (this->Hash() != other_string.Hash())) { | 10031 (this->Hash() != other_string.Hash())) { |
| 10032 return false; // Both sides have a hash code and it does not match. | 10032 return false; // Both sides have a hash code and it does not match. |
| 10033 } | 10033 } |
| 10034 return Equals(other_string, 0, other_string.Length()); | 10034 return Equals(other_string, 0, other_string.Length()); |
| 10035 } | 10035 } |
| 10036 | 10036 |
| 10037 | 10037 |
| 10038 bool String::Equals(const char* utf8_array) const { | 10038 bool String::Equals(const char* str) const { |
|
siva
2012/11/20 19:47:32
yes cstr would be a better name.
Also please chang
cshapiro
2012/11/20 23:41:12
Done.
All of the C-strings in the dart VM are ass
| |
| 10039 ASSERT(utf8_array != NULL); | 10039 ASSERT(str != NULL); |
| 10040 intptr_t len = strlen(utf8_array); | 10040 CodePointIterator it(*this); |
| 10041 for (intptr_t i = 0; i < this->Length(); ++i) { | 10041 intptr_t len = strlen(str); |
| 10042 if (*utf8_array == '\0') { | 10042 while (it.Next()) { |
| 10043 if (*str == '\0') { | |
| 10043 // Lengths don't match. | 10044 // Lengths don't match. |
| 10044 return false; | 10045 return false; |
| 10045 } | 10046 } |
| 10046 int32_t ch; | 10047 int32_t ch; |
| 10047 intptr_t consumed = Utf8::Decode( | 10048 intptr_t consumed = Utf8::Decode(reinterpret_cast<const uint8_t*>(str), |
| 10048 reinterpret_cast<const uint8_t*>(utf8_array), | 10049 len, |
| 10049 len, | 10050 &ch); |
| 10050 &ch); | 10051 if (consumed == 0 || it.Current() != ch) { |
| 10051 if (consumed == 0 || this->CharAt(i) != ch) { | |
| 10052 return false; | 10052 return false; |
| 10053 } | 10053 } |
| 10054 utf8_array += consumed; | 10054 str += consumed; |
| 10055 len -= consumed; | 10055 len -= consumed; |
| 10056 } | 10056 } |
| 10057 return *utf8_array == '\0'; | 10057 return *str == '\0'; |
| 10058 } | 10058 } |
|
siva
2012/11/20 19:47:32
We should add a test case for this in order to ens
cshapiro
2012/11/20 23:41:12
Done.
| |
| 10059 | 10059 |
| 10060 | 10060 |
| 10061 bool String::Equals(const uint8_t* latin1_array, intptr_t len) const { | 10061 bool String::Equals(const uint8_t* latin1_array, intptr_t len) const { |
| 10062 if (len != this->Length()) { | 10062 if (len != this->Length()) { |
| 10063 // Lengths don't match. | 10063 // Lengths don't match. |
| 10064 return false; | 10064 return false; |
| 10065 } | 10065 } |
| 10066 | 10066 |
| 10067 for (intptr_t i = 0; i < len; i++) { | 10067 for (intptr_t i = 0; i < len; i++) { |
| 10068 if (this->CharAt(i) != latin1_array[i]) { | 10068 if (this->CharAt(i) != latin1_array[i]) { |
| (...skipping 2092 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 12161 } | 12161 } |
| 12162 return result.raw(); | 12162 return result.raw(); |
| 12163 } | 12163 } |
| 12164 | 12164 |
| 12165 | 12165 |
| 12166 const char* WeakProperty::ToCString() const { | 12166 const char* WeakProperty::ToCString() const { |
| 12167 return "_WeakProperty"; | 12167 return "_WeakProperty"; |
| 12168 } | 12168 } |
| 12169 | 12169 |
| 12170 } // namespace dart | 12170 } // namespace dart |
| OLD | NEW |