Remove trailing null character from std::string

R=jiayl@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/20159004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@6923 4adac7df-926f-26a2-2b94-8c16560cd09d
diff --git a/webrtc/modules/desktop_capture/window_capturer_win.cc b/webrtc/modules/desktop_capture/window_capturer_win.cc
index 9f19faf..c6555de 100644
--- a/webrtc/modules/desktop_capture/window_capturer_win.cc
+++ b/webrtc/modules/desktop_capture/window_capturer_win.cc
@@ -12,6 +12,7 @@
 
 #include <assert.h>
 
+#include "webrtc/base/win32.h"
 #include "webrtc/modules/desktop_capture/desktop_frame_win.h"
 #include "webrtc/modules/desktop_capture/win/window_capture_utils.h"
 #include "webrtc/system_wrappers/interface/logging.h"
@@ -23,22 +24,6 @@
 
 typedef HRESULT (WINAPI *DwmIsCompositionEnabledFunc)(BOOL* enabled);
 
-// Coverts a zero-terminated UTF-16 string to UTF-8. Returns an empty string if
-// error occurs.
-std::string Utf16ToUtf8(const WCHAR* str) {
-  int len_utf8 = WideCharToMultiByte(CP_UTF8, 0, str, -1,
-                                     NULL, 0, NULL, NULL);
-  if (len_utf8 <= 0)
-    return std::string();
-  std::string result(len_utf8, '\0');
-  int rv = WideCharToMultiByte(CP_UTF8, 0, str, -1,
-                               &*(result.begin()), len_utf8, NULL, NULL);
-  if (rv != len_utf8)
-    assert(false);
-
-  return result;
-}
-
 BOOL CALLBACK WindowsEnumerationHandler(HWND hwnd, LPARAM param) {
   WindowCapturer::WindowList* list =
       reinterpret_cast<WindowCapturer::WindowList*>(param);
@@ -70,7 +55,7 @@
   WCHAR window_title[kTitleLength];
   // Truncate the title if it's longer than kTitleLength.
   GetWindowText(hwnd, window_title, kTitleLength);
-  window.title = Utf16ToUtf8(window_title);
+  window.title = rtc::ToUtf8(window_title);
 
   // Skip windows when we failed to convert the title or it is empty.
   if (window.title.empty())