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 c00397a71fb3c62b673eb8fafba47b9062ff7acc..bb88fd51ab6faea630a5caaabcb43356d6cf3269 100644 |
| --- a/runtime/vm/dart_api_impl.cc |
| +++ b/runtime/vm/dart_api_impl.cc |
| @@ -25,6 +25,7 @@ |
| #include "vm/resolver.h" |
| #include "vm/stack_frame.h" |
| #include "vm/timer.h" |
| +#include "vm/unicode.h" |
| #include "vm/verifier.h" |
| namespace dart { |
| @@ -1611,6 +1612,27 @@ DART_EXPORT Dart_Handle Dart_StringToCString(Dart_Handle object, |
| } |
| +DART_EXPORT Dart_Handle Dart_StringToBytes(Dart_Handle object, |
| + const char** bytes, |
|
cshapiro
2012/05/02 22:10:25
This is typed wrong, this should be a uint8_t, I'l
|
| + 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); |
| + } |
|
siva
2012/05/02 22:15:48
if (bytes == NULL) {
return Api::NewError("%s ex
cshapiro
2012/05/02 22:40:59
Done. As an aside, I think we do not do enough ar
|
| + const char* cstring = str.ToCString(); |
| + *length = Utf8::Length(str); |
| + char* result = reinterpret_cast<char*>(Api::Allocate(isolate, *length)); |
| + if (result == NULL) { |
| + return Api::NewError("Unable to allocate memory"); |
| + } |
| + memmove(result, cstring, *length); |
| + *bytes = result; |
| + return Api::Success(isolate); |
| +} |
| + |
| + |
| // --- Lists --- |