Chromium Code Reviews| 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 #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 Loading... | |
| 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); | |
|
Søren Gjesse
2012/11/13 12:48:45
If the len here and the len above are then same th
Mads Ager (google)
2012/11/13 14:50:17
Yeah, I think I'll save that for a separate change
| |
| 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 } | |
| OLD | NEW |