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 #ifndef BIN_UTILS_WIN_H_ | 5 #ifndef BIN_UTILS_WIN_H_ |
6 #define BIN_UTILS_WIN_H_ | 6 #define BIN_UTILS_WIN_H_ |
7 | 7 |
8 #include "platform/globals.h" | 8 #include "platform/globals.h" |
9 | 9 |
10 namespace dart { | 10 namespace dart { |
(...skipping 19 matching lines...) Expand all Loading... |
30 intptr_t* result_len = NULL); | 30 intptr_t* result_len = NULL); |
31 static const wchar_t* Utf8ToWide(const char* utf8, | 31 static const wchar_t* Utf8ToWide(const char* utf8, |
32 intptr_t len = -1, | 32 intptr_t len = -1, |
33 intptr_t* result_len = NULL); | 33 intptr_t* result_len = NULL); |
34 | 34 |
35 private: | 35 private: |
36 DISALLOW_ALLOCATION(); | 36 DISALLOW_ALLOCATION(); |
37 DISALLOW_IMPLICIT_CONSTRUCTORS(StringUtilsWin); | 37 DISALLOW_IMPLICIT_CONSTRUCTORS(StringUtilsWin); |
38 }; | 38 }; |
39 | 39 |
| 40 // These scopes provide strings converted as indicated by the scope names. |
| 41 // The provided strings are allocated with 'new' and have the same lifetime as |
| 42 // the scope. |
| 43 class WideToUtf8Scope { |
| 44 public: |
| 45 explicit WideToUtf8Scope(const wchar_t* wide) { |
| 46 intptr_t utf8_len = WideCharToMultiByte( |
| 47 CP_UTF8, 0, wide, -1, NULL, 0, NULL, NULL); |
| 48 char* utf8 = new char[utf8_len]; |
| 49 WideCharToMultiByte(CP_UTF8, 0, wide, -1, utf8, utf8_len, NULL, NULL); |
| 50 length_ = utf8_len; |
| 51 utf8_ = utf8; |
| 52 } |
| 53 |
| 54 ~WideToUtf8Scope() { |
| 55 delete[] utf8_; |
| 56 utf8_ = NULL; |
| 57 } |
| 58 |
| 59 char* utf8() const { return utf8_; } |
| 60 intptr_t length() const { return length_; } |
| 61 |
| 62 private: |
| 63 intptr_t length_; |
| 64 char* utf8_; |
| 65 |
| 66 DISALLOW_ALLOCATION(); |
| 67 DISALLOW_IMPLICIT_CONSTRUCTORS(WideToUtf8Scope); |
| 68 }; |
| 69 |
| 70 class Utf8ToWideScope { |
| 71 public: |
| 72 explicit Utf8ToWideScope(const char* utf8) { |
| 73 int wide_len = MultiByteToWideChar(CP_UTF8, 0, utf8, -1, NULL, 0); |
| 74 wchar_t* wide = new wchar_t[wide_len]; |
| 75 MultiByteToWideChar(CP_UTF8, 0, utf8, -1, wide, wide_len); |
| 76 length_ = wide_len; |
| 77 wide_ = wide; |
| 78 } |
| 79 |
| 80 ~Utf8ToWideScope() { |
| 81 delete[] wide_; |
| 82 } |
| 83 |
| 84 wchar_t* wide() const { return wide_; } |
| 85 intptr_t length() const { return length_; } |
| 86 |
| 87 private: |
| 88 intptr_t length_; |
| 89 wchar_t* wide_; |
| 90 |
| 91 DISALLOW_ALLOCATION(); |
| 92 DISALLOW_IMPLICIT_CONSTRUCTORS(Utf8ToWideScope); |
| 93 }; |
| 94 |
40 } // namespace bin | 95 } // namespace bin |
41 } // namespace dart | 96 } // namespace dart |
42 | 97 |
43 #endif // BIN_UTILS_WIN_H_ | 98 #endif // BIN_UTILS_WIN_H_ |
OLD | NEW |