mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
There were two variants of string/wstring conversion utils, one using codecvt_utf8 and the other using codecvt_utf8_utf16. We want the latter, since we want to be using UTF-16, not UCS2.
30 lines
800 B
C++
30 lines
800 B
C++
// Copyright 2013 The Flutter Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#ifndef FLUTTER_FML_PLATFORM_WIN_WSTRING_CONVERSION_H_
|
|
#define FLUTTER_FML_PLATFORM_WIN_WSTRING_CONVERSION_H_
|
|
|
|
#include <codecvt>
|
|
#include <locale>
|
|
#include <string>
|
|
|
|
namespace fml {
|
|
|
|
using WideStringConvertor =
|
|
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t>;
|
|
|
|
inline std::wstring StringToWideString(const std::string& str) {
|
|
WideStringConvertor converter;
|
|
return converter.from_bytes(str);
|
|
}
|
|
|
|
inline std::string WideStringToString(const std::wstring& wstr) {
|
|
WideStringConvertor converter;
|
|
return converter.to_bytes(wstr);
|
|
}
|
|
|
|
} // namespace fml
|
|
|
|
#endif // FLUTTER_FML_PLATFORM_WIN_WSTRING_CONVERSION_H_
|