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

Unified Diff: runtime/bin/utils_win.cc

Issue 11275281: Update dart:io to convert strings between UTF8 and current code page (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments Created 8 years, 1 month 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/utils_macos.cc ('k') | tests/standalone/float_array_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/utils_win.cc
diff --git a/runtime/bin/utils_win.cc b/runtime/bin/utils_win.cc
index 0dba5b5f7af60d343302de0ca3c8961c561d5fef..9ee1777e2466ef1fbb54ef7286dfee272df83595 100644
--- a/runtime/bin/utils_win.cc
+++ b/runtime/bin/utils_win.cc
@@ -45,3 +45,37 @@ void OSError::SetCodeAndMessage(SubSystem sub_system, int code) {
FormatMessageIntoBuffer(code_, message, kMaxMessageLength);
SetMessage(message);
}
+
+char* StringUtils::SystemStringToUtf8(char* str) {
+ int len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
+ wchar_t* unicode = new wchar_t[len+1];
+ MultiByteToWideChar(CP_ACP, 0, str, -1, unicode, len);
+ unicode[len] = '\0';
+ len = WideCharToMultiByte(CP_UTF8, 0, unicode, -1, NULL, 0, NULL, NULL);
+ char* utf8 = reinterpret_cast<char*>(malloc(len+1));
+ WideCharToMultiByte(CP_UTF8, 0, unicode, -1, utf8, len, NULL, NULL);
+ utf8[len] = '\0';
+ delete[] unicode;
+ return utf8;
+}
+
+char* StringUtils::Utf8ToSystemString(char* utf8) {
+ int len = MultiByteToWideChar(CP_UTF8, 0, utf8, -1, NULL, 0);
+ wchar_t* unicode = new wchar_t[len+1];
+ MultiByteToWideChar(CP_UTF8, 0, utf8, -1, unicode, len);
+ unicode[len] = '\0';
+ len = WideCharToMultiByte(CP_ACP, 0, unicode, -1, NULL, 0, NULL, NULL);
+ char* ansi = reinterpret_cast<char*>(malloc(len+1));
+ WideCharToMultiByte(CP_ACP, 0, unicode, -1, ansi, len, NULL, NULL);
+ ansi[len] = '\0';
+ delete[] unicode;
+ return ansi;
+}
+
+const char* StringUtils::Utf8ToSystemString(const char* utf8) {
+ return const_cast<const char*>(Utf8ToSystemString(const_cast<char*>(utf8)));
+}
+
+const char* StringUtils::SystemStringToUtf8(const char* str) {
+ return const_cast<const char*>(Utf8ToSystemString(const_cast<char*>(str)));
+}
« no previous file with comments | « runtime/bin/utils_macos.cc ('k') | tests/standalone/float_array_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698