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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/bin/utils_macos.cc ('k') | tests/standalone/float_array_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include <errno.h> 5 #include <errno.h>
6 6
7 #include "bin/utils.h" 7 #include "bin/utils.h"
8 8
9 static void FormatMessageIntoBuffer(DWORD code, 9 static void FormatMessageIntoBuffer(DWORD code,
10 char* buffer, 10 char* buffer,
(...skipping 27 matching lines...) Expand all
38 38
39 void OSError::SetCodeAndMessage(SubSystem sub_system, int code) { 39 void OSError::SetCodeAndMessage(SubSystem sub_system, int code) {
40 set_sub_system(sub_system); 40 set_sub_system(sub_system);
41 set_code(code); 41 set_code(code);
42 42
43 static const int kMaxMessageLength = 256; 43 static const int kMaxMessageLength = 256;
44 char message[kMaxMessageLength]; 44 char message[kMaxMessageLength];
45 FormatMessageIntoBuffer(code_, message, kMaxMessageLength); 45 FormatMessageIntoBuffer(code_, message, kMaxMessageLength);
46 SetMessage(message); 46 SetMessage(message);
47 } 47 }
48
49 char* StringUtils::SystemStringToUtf8(char* str) {
50 int len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
51 wchar_t* unicode = new wchar_t[len+1];
52 MultiByteToWideChar(CP_ACP, 0, str, -1, unicode, len);
53 unicode[len] = '\0';
54 len = WideCharToMultiByte(CP_UTF8, 0, unicode, -1, NULL, 0, NULL, NULL);
55 char* utf8 = reinterpret_cast<char*>(malloc(len+1));
56 WideCharToMultiByte(CP_UTF8, 0, unicode, -1, utf8, len, NULL, NULL);
57 utf8[len] = '\0';
58 delete[] unicode;
59 return utf8;
60 }
61
62 char* StringUtils::Utf8ToSystemString(char* utf8) {
63 int len = MultiByteToWideChar(CP_UTF8, 0, utf8, -1, NULL, 0);
64 wchar_t* unicode = new wchar_t[len+1];
65 MultiByteToWideChar(CP_UTF8, 0, utf8, -1, unicode, len);
66 unicode[len] = '\0';
67 len = WideCharToMultiByte(CP_ACP, 0, unicode, -1, NULL, 0, NULL, NULL);
68 char* ansi = reinterpret_cast<char*>(malloc(len+1));
69 WideCharToMultiByte(CP_ACP, 0, unicode, -1, ansi, len, NULL, NULL);
70 ansi[len] = '\0';
71 delete[] unicode;
72 return ansi;
73 }
74
75 const char* StringUtils::Utf8ToSystemString(const char* utf8) {
76 return const_cast<const char*>(Utf8ToSystemString(const_cast<char*>(utf8)));
77 }
78
79 const char* StringUtils::SystemStringToUtf8(const char* str) {
80 return const_cast<const char*>(Utf8ToSystemString(const_cast<char*>(str)));
81 }
OLDNEW
« 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