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 RUNTIME_BIN_UTILS_WIN_H_ | 5 #ifndef RUNTIME_BIN_UTILS_WIN_H_ |
6 #define RUNTIME_BIN_UTILS_WIN_H_ | 6 #define RUNTIME_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 25 matching lines...) Expand all Loading... |
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. | 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 | 41 // The provided strings are allocated with 'new' and have the same lifetime as |
42 // the scope. | 42 // the scope. |
43 class WideToUtf8Scope { | 43 class WideToUtf8Scope { |
44 public: | 44 public: |
45 explicit WideToUtf8Scope(const wchar_t* wide) { | 45 explicit WideToUtf8Scope(const wchar_t* wide) { |
46 intptr_t utf8_len = WideCharToMultiByte( | 46 intptr_t utf8_len = |
47 CP_UTF8, 0, wide, -1, NULL, 0, NULL, NULL); | 47 WideCharToMultiByte(CP_UTF8, 0, wide, -1, NULL, 0, NULL, NULL); |
48 char* utf8 = new char[utf8_len]; | 48 char* utf8 = new char[utf8_len]; |
49 WideCharToMultiByte(CP_UTF8, 0, wide, -1, utf8, utf8_len, NULL, NULL); | 49 WideCharToMultiByte(CP_UTF8, 0, wide, -1, utf8, utf8_len, NULL, NULL); |
50 length_ = utf8_len; | 50 length_ = utf8_len; |
51 utf8_ = utf8; | 51 utf8_ = utf8; |
52 } | 52 } |
53 | 53 |
54 ~WideToUtf8Scope() { | 54 ~WideToUtf8Scope() { |
55 delete[] utf8_; | 55 delete[] utf8_; |
56 utf8_ = NULL; | 56 utf8_ = NULL; |
57 } | 57 } |
(...skipping 12 matching lines...) Expand all Loading... |
70 class Utf8ToWideScope { | 70 class Utf8ToWideScope { |
71 public: | 71 public: |
72 explicit Utf8ToWideScope(const char* utf8) { | 72 explicit Utf8ToWideScope(const char* utf8) { |
73 int wide_len = MultiByteToWideChar(CP_UTF8, 0, utf8, -1, NULL, 0); | 73 int wide_len = MultiByteToWideChar(CP_UTF8, 0, utf8, -1, NULL, 0); |
74 wchar_t* wide = new wchar_t[wide_len]; | 74 wchar_t* wide = new wchar_t[wide_len]; |
75 MultiByteToWideChar(CP_UTF8, 0, utf8, -1, wide, wide_len); | 75 MultiByteToWideChar(CP_UTF8, 0, utf8, -1, wide, wide_len); |
76 length_ = wide_len; | 76 length_ = wide_len; |
77 wide_ = wide; | 77 wide_ = wide; |
78 } | 78 } |
79 | 79 |
80 ~Utf8ToWideScope() { | 80 ~Utf8ToWideScope() { delete[] wide_; } |
81 delete[] wide_; | |
82 } | |
83 | 81 |
84 wchar_t* wide() const { return wide_; } | 82 wchar_t* wide() const { return wide_; } |
85 intptr_t length() const { return length_; } | 83 intptr_t length() const { return length_; } |
86 | 84 |
87 private: | 85 private: |
88 intptr_t length_; | 86 intptr_t length_; |
89 wchar_t* wide_; | 87 wchar_t* wide_; |
90 | 88 |
91 DISALLOW_ALLOCATION(); | 89 DISALLOW_ALLOCATION(); |
92 DISALLOW_IMPLICIT_CONSTRUCTORS(Utf8ToWideScope); | 90 DISALLOW_IMPLICIT_CONSTRUCTORS(Utf8ToWideScope); |
93 }; | 91 }; |
94 | 92 |
95 } // namespace bin | 93 } // namespace bin |
96 } // namespace dart | 94 } // namespace dart |
97 | 95 |
98 #endif // RUNTIME_BIN_UTILS_WIN_H_ | 96 #endif // RUNTIME_BIN_UTILS_WIN_H_ |
OLD | NEW |