| Index: runtime/bin/utils_win.h
|
| diff --git a/runtime/bin/utils_win.h b/runtime/bin/utils_win.h
|
| index fe0fa5c814069cdc1ae1ad04ef6de085f1544098..3e7fa4c982e4e535b8047149ffe0a093a8189ebb 100644
|
| --- a/runtime/bin/utils_win.h
|
| +++ b/runtime/bin/utils_win.h
|
| @@ -37,6 +37,61 @@ class StringUtilsWin {
|
| DISALLOW_IMPLICIT_CONSTRUCTORS(StringUtilsWin);
|
| };
|
|
|
| +// These scopes provide strings converted as indicated by the scope names.
|
| +// The provided strings are allocated with 'new' and have the same lifetime as
|
| +// the scope.
|
| +class WideToUtf8Scope {
|
| + public:
|
| + explicit WideToUtf8Scope(const wchar_t* wide) {
|
| + intptr_t utf8_len = WideCharToMultiByte(
|
| + CP_UTF8, 0, wide, -1, NULL, 0, NULL, NULL);
|
| + char* utf8 = new char[utf8_len];
|
| + WideCharToMultiByte(CP_UTF8, 0, wide, -1, utf8, utf8_len, NULL, NULL);
|
| + length_ = utf8_len;
|
| + utf8_ = utf8;
|
| + }
|
| +
|
| + ~WideToUtf8Scope() {
|
| + delete[] utf8_;
|
| + utf8_ = NULL;
|
| + }
|
| +
|
| + char* utf8() const { return utf8_; }
|
| + intptr_t length() const { return length_; }
|
| +
|
| + private:
|
| + intptr_t length_;
|
| + char* utf8_;
|
| +
|
| + DISALLOW_ALLOCATION();
|
| + DISALLOW_IMPLICIT_CONSTRUCTORS(WideToUtf8Scope);
|
| +};
|
| +
|
| +class Utf8ToWideScope {
|
| + public:
|
| + explicit Utf8ToWideScope(const char* utf8) {
|
| + int wide_len = MultiByteToWideChar(CP_UTF8, 0, utf8, -1, NULL, 0);
|
| + wchar_t* wide = new wchar_t[wide_len];
|
| + MultiByteToWideChar(CP_UTF8, 0, utf8, -1, wide, wide_len);
|
| + length_ = wide_len;
|
| + wide_ = wide;
|
| + }
|
| +
|
| + ~Utf8ToWideScope() {
|
| + delete[] wide_;
|
| + }
|
| +
|
| + wchar_t* wide() const { return wide_; }
|
| + intptr_t length() const { return length_; }
|
| +
|
| + private:
|
| + intptr_t length_;
|
| + wchar_t* wide_;
|
| +
|
| + DISALLOW_ALLOCATION();
|
| + DISALLOW_IMPLICIT_CONSTRUCTORS(Utf8ToWideScope);
|
| +};
|
| +
|
| } // namespace bin
|
| } // namespace dart
|
|
|
|
|