Chromium Code Reviews| Index: runtime/vm/dart_api_impl.cc |
| diff --git a/runtime/vm/dart_api_impl.cc b/runtime/vm/dart_api_impl.cc |
| index 06e63a2950a4dd879cc0a1d6715e6901c3b92f62..da2340bebc11caa779afcb57dc127b0271d62766 100644 |
| --- a/runtime/vm/dart_api_impl.cc |
| +++ b/runtime/vm/dart_api_impl.cc |
| @@ -791,11 +791,47 @@ DART_EXPORT Dart_Handle Dart_NewString32(const uint32_t* codepoints, |
| } |
| +DART_EXPORT Dart_Handle Dart_NewExternalString8(uint8_t* codepoints, |
| + intptr_t length, |
| + void* peer, |
| + Dart_PeerFinalizer callback) { |
| + Zone zone; // Setup a VM zone as we are creating some handles. |
| + HandleScope scope; // Setup a VM handle scope. |
|
siva
2011/11/18 23:26:09
When you sync up these two lines will be replaced
cshapiro
2011/11/19 01:08:29
Thanks for pointing this out. I discovered the ch
|
| + const String& obj = |
| + String::Handle(String::NewExternal(codepoints, length, peer, callback)); |
| + return Api::NewLocalHandle(obj); |
| +} |
| + |
| + |
| +DART_EXPORT Dart_Handle Dart_NewExternalString16(uint16_t* codepoints, |
| + intptr_t length, |
| + void* peer, |
| + Dart_PeerFinalizer callback) { |
| + Zone zone; // Setup a VM zone as we are creating some handles. |
| + HandleScope scope; // Setup a VM handle scope. |
| + const String& obj = |
| + String::Handle(String::NewExternal(codepoints, length, peer, callback)); |
| + return Api::NewLocalHandle(obj); |
| +} |
| + |
| + |
| +DART_EXPORT Dart_Handle Dart_NewExternalString32(uint32_t* codepoints, |
| + intptr_t length, |
| + void* peer, |
| + Dart_PeerFinalizer callback) { |
| + Zone zone; // Setup a VM zone as we are creating some handles. |
| + HandleScope scope; // Setup a VM handle scope. |
| + const String& obj = |
| + String::Handle(String::NewExternal(codepoints, length, peer, callback)); |
| + return Api::NewLocalHandle(obj); |
| +} |
| + |
| + |
| DART_EXPORT bool Dart_IsString8(Dart_Handle object) { |
| Zone zone; // Setup a VM zone as we are creating some handles. |
| HandleScope scope; // Setup a VM handle scope. |
| const Object& obj = Object::Handle(Api::UnwrapHandle(object)); |
| - return obj.IsOneByteString(); |
| + return obj.IsOneByteString() || obj.IsExternalOneByteString(); |
| } |
| @@ -803,7 +839,8 @@ DART_EXPORT bool Dart_IsString16(Dart_Handle object) { |
| Zone zone; // Setup a VM zone as we are creating some handles. |
| HandleScope scope; // Setup a VM handle scope. |
| const Object& obj = Object::Handle(Api::UnwrapHandle(object)); |
| - return obj.IsOneByteString() || obj.IsTwoByteString(); |
| + return (obj.IsOneByteString() || obj.IsExternalOneByteString() || |
| + obj.IsTwoByteString() || obj.IsExternalOneByteString()); |
|
Ivan Posva
2011/11/18 19:36:44
obj.IsExternalOneByteString() -> obj.IsExternalTwo
cshapiro
2011/11/19 01:08:29
Fixed. I could not find any tests for this functi
|
| } |
| @@ -813,16 +850,18 @@ DART_EXPORT Dart_Handle Dart_StringGet8(Dart_Handle str, |
| Zone zone; // Setup a VM zone as we are creating some handles. |
| HandleScope scope; // Setup a VM handle scope. |
| const Object& obj = Object::Handle(Api::UnwrapHandle(str)); |
| - if (obj.IsOneByteString()) { |
| - OneByteString& string_obj = OneByteString::Handle(); |
| + if (obj.IsString()) { |
| + String& string_obj = String::Handle(); |
|
siva
2011/11/18 23:26:09
If you manage to get your change in before Todd th
|
| string_obj ^= obj.raw(); |
| - intptr_t str_len = string_obj.Length(); |
| - intptr_t copy_len = (str_len > *length) ? *length : str_len; |
| - for (intptr_t i = 0; i < copy_len; i++) { |
| - codepoints[i] = static_cast<uint8_t>(string_obj.CharAt(i)); |
| + if (string_obj.CharSize() == String::kOneByteChar) { |
| + intptr_t str_len = string_obj.Length(); |
| + intptr_t copy_len = (str_len > *length) ? *length : str_len; |
| + for (intptr_t i = 0; i < copy_len; i++) { |
| + codepoints[i] = static_cast<uint8_t>(string_obj.CharAt(i)); |
| + } |
| + *length= copy_len; |
| + return Api::Success(); |
| } |
| - *length= copy_len; |
| - return Api::Success(); |
| } |
| return Api::Error(obj.IsString() |
| ? "Object is not a String8" |
| @@ -836,16 +875,18 @@ DART_EXPORT Dart_Handle Dart_StringGet16(Dart_Handle str, |
| Zone zone; // Setup a VM zone as we are creating some handles. |
| HandleScope scope; // Setup a VM handle scope. |
| const Object& obj = Object::Handle(Api::UnwrapHandle(str)); |
| - if (obj.IsOneByteString() || obj.IsTwoByteString()) { |
| + if (obj.IsString()) { |
| String& string_obj = String::Handle(); |
| string_obj ^= obj.raw(); |
| - intptr_t str_len = string_obj.Length(); |
| - intptr_t copy_len = (str_len > *length) ? *length : str_len; |
| - for (intptr_t i = 0; i < copy_len; i++) { |
| - codepoints[i] = static_cast<uint16_t>(string_obj.CharAt(i)); |
| + if (string_obj.CharSize() <= String::kTwoByteChar) { |
| + intptr_t str_len = string_obj.Length(); |
| + intptr_t copy_len = (str_len > *length) ? *length : str_len; |
| + for (intptr_t i = 0; i < copy_len; i++) { |
| + codepoints[i] = static_cast<uint16_t>(string_obj.CharAt(i)); |
| + } |
| + *length = copy_len; |
| + return Api::Success(); |
| } |
| - *length = copy_len; |
| - return Api::Success(); |
| } |
| return Api::Error(obj.IsString() |
| ? "Object is not a String16" |