Flutter Windows Embedder
wchar_util.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
6 
7 #include <dwmapi.h>
8 
9 namespace flutter {
10 
11 std::string WCharBufferToString(const wchar_t* wstr) {
12  if (!wstr) {
13  return "";
14  }
15 
16  int buffer_size = WideCharToMultiByte(CP_UTF8, //
17  0, //
18  wstr, //
19  -1, //
20  nullptr, //
21  0, //
22  nullptr, //
23  nullptr //
24  );
25  if (buffer_size <= 0) {
26  return "";
27  }
28 
29  std::string result(buffer_size - 1, 0);
30  WideCharToMultiByte(CP_UTF8, //
31  0, //
32  wstr, //
33  -1, //
34  result.data(), //
35  buffer_size, //
36  nullptr, //
37  nullptr //
38  );
39  return result;
40 }
41 
42 } // namespace flutter
std::string WCharBufferToString(const wchar_t *wstr)
Convert a null terminated wchar_t buffer to a std::string using Windows utilities.
Definition: wchar_util.cc:11