summaryrefslogtreecommitdiffstats
path: root/base/logging.cc
diff options
context:
space:
mode:
authorbrettw@google.com <brettw@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-07 03:11:42 +0000
committerbrettw@google.com <brettw@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-07 03:11:42 +0000
commit15af80eb0cb603cf5a365cb86061bad95f063d40 (patch)
treedf2a4465e17cfe58b747bab9042df9134a571146 /base/logging.cc
parentac2800f20948f30c17ff41be93bcee5540c0952c (diff)
downloadchromium_src-15af80eb0cb603cf5a365cb86061bad95f063d40.zip
chromium_src-15af80eb0cb603cf5a365cb86061bad95f063d40.tar.gz
chromium_src-15af80eb0cb603cf5a365cb86061bad95f063d40.tar.bz2
This is the addition of the system-dependent string conversions. This is just the new code and changing logging to use it. I will change other things to use this and delete the code in string_util in a subsequent pass.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@479 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/logging.cc')
-rw-r--r--base/logging.cc31
1 files changed, 8 insertions, 23 deletions
diff --git a/base/logging.cc b/base/logging.cc
index eba177e..ca9905d 100644
--- a/base/logging.cc
+++ b/base/logging.cc
@@ -36,6 +36,7 @@
#include "base/command_line.h"
#include "base/lock_impl.h"
#include "base/logging.h"
+#include "base/sys_string_conversions.h"
namespace logging {
@@ -207,28 +208,24 @@ void DisplayDebugMessage(const std::string& str) {
backslash[1] = 0;
wcscat_s(prog_name, MAX_PATH, L"debug_message.exe");
- // stupid CreateProcess requires a non-const command line and may modify it.
- // We also want to use the wide string
- int charcount = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, NULL, 0);
- if (!charcount)
- return;
- scoped_array<wchar_t> cmdline(new wchar_t[charcount]);
- if (!MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, cmdline.get(), charcount))
- return;
+ // Stupid CreateProcess requires a non-const command line and may modify it.
+ // We also want to use the wide string.
+ std::wstring cmdline_string = base::SysUTF8ToWide(str);
+ wchar_t* cmdline = const_cast<wchar_t*>(cmdline_string.c_str());
STARTUPINFO startup_info;
memset(&startup_info, 0, sizeof(startup_info));
startup_info.cb = sizeof(startup_info);
PROCESS_INFORMATION process_info;
- if (CreateProcessW(prog_name, cmdline.get(), NULL, NULL, false, 0, NULL,
+ if (CreateProcessW(prog_name, cmdline, NULL, NULL, false, 0, NULL,
NULL, &startup_info, &process_info)) {
WaitForSingleObject(process_info.hProcess, INFINITE);
CloseHandle(process_info.hThread);
CloseHandle(process_info.hProcess);
} else {
// debug process broken, let's just do a message box
- MessageBoxW(NULL, cmdline.get(), L"Fatal error",
+ MessageBoxW(NULL, cmdline, L"Fatal error",
MB_OK | MB_ICONHAND | MB_TOPMOST);
}
}
@@ -380,17 +377,5 @@ void CloseLogFile() {
} // namespace logging
std::ostream& operator<<(std::ostream& out, const wchar_t* wstr) {
- if (!wstr || !wstr[0])
- return out;
-
- // compute the length of the buffer we'll need
- int charcount = WideCharToMultiByte(CP_UTF8, 0, wstr, -1,
- NULL, 0, NULL, NULL);
- if (charcount == 0)
- return out;
-
- // convert
- scoped_array<char> buf(new char[charcount]);
- WideCharToMultiByte(CP_UTF8, 0, wstr, -1, buf.get(), charcount, NULL, NULL);
- return out << buf.get();
+ return out << base::SysWideToUTF8(std::wstring(wstr));
}