Audacity 3.2.0
CodeConversions.cpp
Go to the documentation of this file.
1/*!********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 @file CodeConversions.cpp
6 @brief Define functions to perform UTF-8 to std::wstring conversions.
7
8 Dmitry Vedenko
9 **********************************************************************/
10
11#include "CodeConversions.h"
12
13#include <locale>
14#include <codecvt>
15
16namespace audacity
17{
18
19std::string ToUTF8 (const std::wstring& wstr)
20{
21 return std::wstring_convert<std::codecvt_utf8<wchar_t>> ().to_bytes (wstr);
22}
23
24std::string ToUTF8 (const wchar_t* wstr)
25{
26 return std::wstring_convert<std::codecvt_utf8<wchar_t>> ().to_bytes (wstr);
27}
28
29std::string ToUTF8 (const wxString& wstr)
30{
31 return wstr.ToStdString (wxGet_wxConvUTF8 ());
32}
33
34std::wstring ToWString (const std::string& str)
35{
36 return std::wstring_convert<std::codecvt_utf8<wchar_t>> ().from_bytes (str);
37}
38
39STRING_UTILS_API std::wstring ToWString(std::string_view str)
40{
41 return std::wstring_convert<std::codecvt_utf8<wchar_t>>().from_bytes(
42 str.data(), str.data() + str.length());
43}
44
45std::wstring ToWString (const char* str)
46{
47 return std::wstring_convert<std::codecvt_utf8<wchar_t>> ().from_bytes (str);
48}
49
50std::wstring ToWString (const wxString& str)
51{
52 return str.ToStdWstring ();
53}
54
55wxString ToWXString (const std::string& str)
56{
57 return wxString::FromUTF8 (str);
58}
59
60STRING_UTILS_API wxString ToWXString(std::string_view str)
61{
62 return wxString::FromUTF8(str.data(), str.length());
63}
64
65STRING_UTILS_API wxString ToWXString(const char* str)
66{
67 return wxString::FromUTF8(str);
68}
69
70wxString ToWXString (const std::wstring& str)
71{
72 return wxString (str);
73}
74
75wxString ToWXString(std::wstring_view str)
76{
77 return wxString(str.data(), str.size());
78}
79
80wxString ToWXString(const wchar_t* str)
81{
82 return wxString(str);
83}
84
85}
Declare functions to perform UTF-8 to std::wstring conversions.
#define str(a)
std::string ToUTF8(const std::wstring &wstr)
std::wstring ToWString(const std::string &str)
wxString ToWXString(const std::string &str)