| Index: vm/dart_api_impl.cc
|
| ===================================================================
|
| --- vm/dart_api_impl.cc (revision 14046)
|
| +++ vm/dart_api_impl.cc (working copy)
|
| @@ -273,13 +273,6 @@
|
| *peer = data->peer();
|
| return true;
|
| }
|
| - case kExternalFourByteStringCid: {
|
| - RawExternalFourByteString* raw_string =
|
| - reinterpret_cast<RawExternalFourByteString*>(raw_obj)->ptr();
|
| - ExternalStringData<uint32_t>* data = raw_string->external_data_;
|
| - *peer = data->peer();
|
| - return true;
|
| - }
|
| }
|
| return false;
|
| }
|
| @@ -1522,16 +1515,6 @@
|
| }
|
|
|
|
|
| -DART_EXPORT bool Dart_IsString8(Dart_Handle object) {
|
| - return RawObject::IsOneByteStringClassId(Api::ClassId(object));
|
| -}
|
| -
|
| -
|
| -DART_EXPORT bool Dart_IsString16(Dart_Handle object) {
|
| - return RawObject::IsTwoByteStringClassId(Api::ClassId(object));
|
| -}
|
| -
|
| -
|
| DART_EXPORT Dart_Handle Dart_StringLength(Dart_Handle str, intptr_t* len) {
|
| Isolate* isolate = Isolate::Current();
|
| DARTSCOPE(isolate);
|
| @@ -1544,7 +1527,7 @@
|
| }
|
|
|
|
|
| -DART_EXPORT Dart_Handle Dart_NewString(const char* str) {
|
| +DART_EXPORT Dart_Handle Dart_NewStringFromCString(const char* str) {
|
| Isolate* isolate = Isolate::Current();
|
| DARTSCOPE(isolate);
|
| if (str == NULL) {
|
| @@ -1558,39 +1541,39 @@
|
| }
|
|
|
|
|
| -DART_EXPORT Dart_Handle Dart_NewString8(const uint8_t* codepoints,
|
| - intptr_t length) {
|
| +DART_EXPORT Dart_Handle Dart_NewStringFromUTF8(const uint8_t* utf8_array,
|
| + intptr_t length) {
|
| Isolate* isolate = Isolate::Current();
|
| DARTSCOPE(isolate);
|
| - if (codepoints == NULL && length != 0) {
|
| - RETURN_NULL_ERROR(codepoints);
|
| + if (utf8_array == NULL && length != 0) {
|
| + RETURN_NULL_ERROR(utf8_array);
|
| }
|
| CHECK_LENGTH(length, String::kMaxElements);
|
| - return Api::NewHandle(isolate, String::New(codepoints, length));
|
| + return Api::NewHandle(isolate, String::New(utf8_array, length));
|
| }
|
|
|
|
|
| -DART_EXPORT Dart_Handle Dart_NewString16(const uint16_t* codepoints,
|
| - intptr_t length) {
|
| +DART_EXPORT Dart_Handle Dart_NewStringFromUTF16(const uint16_t* utf16_array,
|
| + intptr_t length) {
|
| Isolate* isolate = Isolate::Current();
|
| DARTSCOPE(isolate);
|
| - if (codepoints == NULL && length != 0) {
|
| - RETURN_NULL_ERROR(codepoints);
|
| + if (utf16_array == NULL && length != 0) {
|
| + RETURN_NULL_ERROR(utf16_array);
|
| }
|
| CHECK_LENGTH(length, String::kMaxElements);
|
| - return Api::NewHandle(isolate, String::New(codepoints, length));
|
| + return Api::NewHandle(isolate, String::New(utf16_array, length));
|
| }
|
|
|
|
|
| -DART_EXPORT Dart_Handle Dart_NewString32(const uint32_t* codepoints,
|
| - intptr_t length) {
|
| +DART_EXPORT Dart_Handle Dart_NewStringFromUTF32(const uint32_t* utf32_array,
|
| + intptr_t length) {
|
| Isolate* isolate = Isolate::Current();
|
| DARTSCOPE(isolate);
|
| - if (codepoints == NULL && length != 0) {
|
| - RETURN_NULL_ERROR(codepoints);
|
| + if (utf32_array == NULL && length != 0) {
|
| + RETURN_NULL_ERROR(utf32_array);
|
| }
|
| CHECK_LENGTH(length, String::kMaxElements);
|
| - return Api::NewHandle(isolate, String::New(codepoints, length));
|
| + return Api::NewHandle(isolate, String::New(utf32_array, length));
|
| }
|
|
|
|
|
| @@ -1623,95 +1606,79 @@
|
| }
|
|
|
|
|
| -DART_EXPORT Dart_Handle Dart_NewExternalString8(const uint8_t* codepoints,
|
| - intptr_t length,
|
| - void* peer,
|
| - Dart_PeerFinalizer callback) {
|
| +DART_EXPORT Dart_Handle Dart_NewExternalUTF8String(const uint8_t* utf8_array,
|
| + intptr_t length,
|
| + void* peer,
|
| + Dart_PeerFinalizer cback) {
|
| Isolate* isolate = Isolate::Current();
|
| DARTSCOPE(isolate);
|
| - if (codepoints == NULL && length != 0) {
|
| - RETURN_NULL_ERROR(codepoints);
|
| + if (utf8_array == NULL && length != 0) {
|
| + RETURN_NULL_ERROR(utf8_array);
|
| }
|
| CHECK_LENGTH(length, String::kMaxElements);
|
| - return Api::NewHandle(
|
| - isolate, String::NewExternal(codepoints, length, peer, callback));
|
| + return Api::NewHandle(isolate,
|
| + String::NewExternal(utf8_array, length, peer, cback));
|
| }
|
|
|
|
|
| -DART_EXPORT Dart_Handle Dart_NewExternalString16(const uint16_t* codepoints,
|
| - intptr_t length,
|
| - void* peer,
|
| - Dart_PeerFinalizer callback) {
|
| +DART_EXPORT Dart_Handle Dart_NewExternalUTF16String(const uint16_t* utf16_array,
|
| + intptr_t length,
|
| + void* peer,
|
| + Dart_PeerFinalizer cback) {
|
| Isolate* isolate = Isolate::Current();
|
| DARTSCOPE(isolate);
|
| - if (codepoints == NULL && length != 0) {
|
| - RETURN_NULL_ERROR(codepoints);
|
| + if (utf16_array == NULL && length != 0) {
|
| + RETURN_NULL_ERROR(utf16_array);
|
| }
|
| CHECK_LENGTH(length, String::kMaxElements);
|
| - return Api::NewHandle(
|
| - isolate, String::NewExternal(codepoints, length, peer, callback));
|
| + return Api::NewHandle(isolate,
|
| + String::NewExternal(utf16_array, length, peer, cback));
|
| }
|
|
|
|
|
| -DART_EXPORT Dart_Handle Dart_NewExternalString32(const uint32_t* codepoints,
|
| - intptr_t length,
|
| - void* peer,
|
| - Dart_PeerFinalizer callback) {
|
| +DART_EXPORT Dart_Handle Dart_StringAsCString(Dart_Handle object,
|
| + const char** cstr) {
|
| Isolate* isolate = Isolate::Current();
|
| DARTSCOPE(isolate);
|
| - if (codepoints == NULL && length != 0) {
|
| - RETURN_NULL_ERROR(codepoints);
|
| - }
|
| - CHECK_LENGTH(length, String::kMaxElements);
|
| - return Api::NewHandle(
|
| - isolate, String::NewExternal(codepoints, length, peer, callback));
|
| -}
|
| -
|
| -
|
| -DART_EXPORT Dart_Handle Dart_StringGet8(Dart_Handle str,
|
| - uint8_t* codepoints,
|
| - intptr_t* length) {
|
| - Isolate* isolate = Isolate::Current();
|
| - DARTSCOPE(isolate);
|
| - const OneByteString& str_obj = Api::UnwrapOneByteStringHandle(isolate, str);
|
| + const String& str_obj = Api::UnwrapStringHandle(isolate, object);
|
| if (str_obj.IsNull()) {
|
| - RETURN_TYPE_ERROR(isolate, str, String8);
|
| + RETURN_TYPE_ERROR(isolate, object, String);
|
| }
|
| - intptr_t str_len = str_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>(str_obj.CharAt(i));
|
| + intptr_t string_length = Utf8::Length(str_obj);
|
| + char* res = Api::TopScope(isolate)->zone()->Alloc<char>(string_length + 1);
|
| + if (res == NULL) {
|
| + return Api::NewError("Unable to allocate memory");
|
| }
|
| - *length= copy_len;
|
| + const char* string_value = str_obj.ToCString();
|
| + memmove(res, string_value, string_length + 1);
|
| + ASSERT(res[string_length] == '\0');
|
| + *cstr = res;
|
| return Api::Success(isolate);
|
| }
|
|
|
|
|
| -DART_EXPORT Dart_Handle Dart_StringGet16(Dart_Handle str,
|
| - uint16_t* codepoints,
|
| - intptr_t* length) {
|
| +DART_EXPORT Dart_Handle Dart_StringAsUTF8(Dart_Handle str,
|
| + uint8_t* utf8_array,
|
| + intptr_t* length) {
|
| Isolate* isolate = Isolate::Current();
|
| DARTSCOPE(isolate);
|
| const String& str_obj = Api::UnwrapStringHandle(isolate, str);
|
| if (str_obj.IsNull()) {
|
| RETURN_TYPE_ERROR(isolate, str, String);
|
| }
|
| - if (str_obj.CharSize() > String::kTwoByteChar) {
|
| - return Api::NewError("Object is not a String16 or String8");
|
| - }
|
| intptr_t str_len = str_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>(str_obj.CharAt(i));
|
| + if (str_len > *length) {
|
| + return Api::NewError("Input array is not large enough to hold the result");
|
| }
|
| - *length = copy_len;
|
| + str_obj.ToUTF8(utf8_array, str_len);
|
| + *length= str_len;
|
| return Api::Success(isolate);
|
| }
|
|
|
|
|
| -DART_EXPORT Dart_Handle Dart_StringGet32(Dart_Handle str,
|
| - uint32_t* codepoints,
|
| - intptr_t* length) {
|
| +DART_EXPORT Dart_Handle Dart_StringAsUTF16(Dart_Handle str,
|
| + uint16_t* utf16_array,
|
| + intptr_t* length) {
|
| Isolate* isolate = Isolate::Current();
|
| DARTSCOPE(isolate);
|
| const String& str_obj = Api::UnwrapStringHandle(isolate, str);
|
| @@ -1721,61 +1688,13 @@
|
| intptr_t str_len = str_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<uint32_t>(str_obj.CharAt(i));
|
| + utf16_array[i] = static_cast<uint16_t>(str_obj.CharAt(i));
|
| }
|
| *length = copy_len;
|
| return Api::Success(isolate);
|
| }
|
|
|
|
|
| -DART_EXPORT Dart_Handle Dart_StringToCString(Dart_Handle object,
|
| - const char** result) {
|
| - Isolate* isolate = Isolate::Current();
|
| - DARTSCOPE(isolate);
|
| - const String& str_obj = Api::UnwrapStringHandle(isolate, object);
|
| - if (str_obj.IsNull()) {
|
| - RETURN_TYPE_ERROR(isolate, object, String);
|
| - }
|
| - intptr_t string_length = Utf8::Length(str_obj);
|
| - char* res = Api::TopScope(isolate)->zone()->Alloc<char>(string_length + 1);
|
| - if (res == NULL) {
|
| - return Api::NewError("Unable to allocate memory");
|
| - }
|
| - const char* string_value = str_obj.ToCString();
|
| - memmove(res, string_value, string_length + 1);
|
| - ASSERT(res[string_length] == '\0');
|
| - *result = res;
|
| - return Api::Success(isolate);
|
| -}
|
| -
|
| -
|
| -DART_EXPORT Dart_Handle Dart_StringToBytes(Dart_Handle object,
|
| - const uint8_t** bytes,
|
| - intptr_t *length) {
|
| - Isolate* isolate = Isolate::Current();
|
| - DARTSCOPE(isolate);
|
| - const String& str = Api::UnwrapStringHandle(isolate, object);
|
| - if (str.IsNull()) {
|
| - RETURN_TYPE_ERROR(isolate, object, String);
|
| - }
|
| - if (bytes == NULL) {
|
| - RETURN_NULL_ERROR(bytes);
|
| - }
|
| - if (length == NULL) {
|
| - RETURN_NULL_ERROR(length);
|
| - }
|
| - const char* cstring = str.ToCString();
|
| - *length = Utf8::Length(str);
|
| - uint8_t* result = Api::TopScope(isolate)->zone()->Alloc<uint8_t>(*length);
|
| - if (result == NULL) {
|
| - return Api::NewError("Unable to allocate memory");
|
| - }
|
| - memmove(result, cstring, *length);
|
| - *bytes = result;
|
| - return Api::Success(isolate);
|
| -}
|
| -
|
| -
|
| // --- Lists ---
|
|
|
|
|
|
|