Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(561)

Unified Diff: runtime/bin/utils_win.h

Issue 2439173002: [windows] Make most file_win.cc functions use malloc for string conversions. (Closed)
Patch Set: Fix typo Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/bin/socket_win.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « runtime/bin/socket_win.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698