xref: /third_party/gn/src/base/win/win_util.h (revision 6d528ed9)
16d528ed9Sopenharmony_ci// Copyright 2019 The Chromium Authors. All rights reserved.
26d528ed9Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be
36d528ed9Sopenharmony_ci// found in the LICENSE file.
46d528ed9Sopenharmony_ci
56d528ed9Sopenharmony_ci#ifndef BASE_WIN_WIN_UTIL_H_
66d528ed9Sopenharmony_ci#define BASE_WIN_WIN_UTIL_H_
76d528ed9Sopenharmony_ci
86d528ed9Sopenharmony_ci#include <string>
96d528ed9Sopenharmony_ci#include <string_view>
106d528ed9Sopenharmony_ci
116d528ed9Sopenharmony_cinamespace base {
126d528ed9Sopenharmony_ci
136d528ed9Sopenharmony_ci// Windows API calls take wchar_t but on that platform wchar_t should be the
146d528ed9Sopenharmony_ci// same as a char16_t.
156d528ed9Sopenharmony_ciinline const wchar_t* ToWCharT(const std::u16string* s) {
166d528ed9Sopenharmony_ci  static_assert(sizeof(std::u16string::value_type) == sizeof(wchar_t));
176d528ed9Sopenharmony_ci  return reinterpret_cast<const wchar_t*>(s->c_str());
186d528ed9Sopenharmony_ci}
196d528ed9Sopenharmony_ci
206d528ed9Sopenharmony_ciinline const wchar_t* ToWCharT(const char16_t* s) {
216d528ed9Sopenharmony_ci  return reinterpret_cast<const wchar_t*>(s);
226d528ed9Sopenharmony_ci}
236d528ed9Sopenharmony_ci
246d528ed9Sopenharmony_ciinline wchar_t* ToWCharT(char16_t* s) {
256d528ed9Sopenharmony_ci  return reinterpret_cast<wchar_t*>(s);
266d528ed9Sopenharmony_ci}
276d528ed9Sopenharmony_ci
286d528ed9Sopenharmony_ci}  // namespace base
296d528ed9Sopenharmony_ci
306d528ed9Sopenharmony_ci#endif  // BASE_WIN_WIN_UTIL_H_
31