1 /*
2 * Copyright (C) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "str_convert.h"
17
18 #include <codecvt>
19
20 namespace OHOS {
21 namespace Telephony {
ToUtf16(std::string str)22 std::u16string ToUtf16(std::string str)
23 {
24 return std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> {}.from_bytes(str);
25 }
26
ToUtf8(std::u16string str16)27 std::string ToUtf8(std::u16string str16)
28 {
29 return std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> {}.to_bytes(str16);
30 }
31
ToUtf32(std::string str)32 std::u32string ToUtf32(std::string str)
33 {
34 return std::wstring_convert<std::codecvt_utf8<char32_t>, char32_t> {}.from_bytes(str);
35 }
36
ToUtf8(std::u32string str32)37 std::string ToUtf8(std::u32string str32)
38 {
39 return std::wstring_convert<std::codecvt_utf8<char32_t>, char32_t> {}.to_bytes(str32);
40 }
41
ToUtf8(std::wstring wstr)42 std::string ToUtf8(std::wstring wstr)
43 {
44 return std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> {}.to_bytes(wstr);
45 }
46 } // namespace Telephony
47 } // namespace OHOS