19 out.
assign(stringView.size(), L
'\0');
20 std::use_facet<std::ctype<wchar_t>>(locale).widen(
22 stringView.data() + stringView.size(),
38 inline wstring_view
to_wstring(wstring_view stringView,
const std::locale& locale)
47 out.
assign(stringView.size(),
'\0');
48 std::use_facet<std::ctype<wchar_t>>(locale)
49 .narrow(stringView.data(), stringView.data() + stringView.size(),
'?', out.data());
64 inline cstring_view
to_cstring(cstring_view stringView,
const std::locale& locale)
69 inline void to_string(
string& out, cstring_view stringView,
const std::locale& locale)
71 #if QX_CONF_CHAR == QX_CHAR_T_CHAR
73 #elif QX_CONF_CHAR == QX_CHAR_T_WCHAR_T
76 #error Unsupported char type
80 inline string to_string(cstring_view stringView,
const std::locale& locale)
82 #if QX_CONF_CHAR == QX_CHAR_T_CHAR
84 #elif QX_CONF_CHAR == QX_CHAR_T_WCHAR_T
87 #error Unsupported char type
91 inline void to_string(
string& out, wstring_view stringView,
const std::locale& locale)
93 #if QX_CONF_CHAR == QX_CHAR_T_CHAR
95 #elif QX_CONF_CHAR == QX_CHAR_T_WCHAR_T
98 #error Unsupported char type
102 inline string to_string(wstring_view stringView,
const std::locale& locale)
104 #if QX_CONF_CHAR == QX_CHAR_T_CHAR
106 #elif QX_CONF_CHAR == QX_CHAR_T_WCHAR_T
109 #error Unsupported char type
117 #if QX_CONF_CHAR == QX_CHAR_T_CHAR
119 #elif QX_CONF_CHAR == QX_CHAR_T_WCHAR_T
123 const int nLength = MultiByteToWideChar(CP_UTF8, 0, utf8.data(),
static_cast<int>(utf8.size()),
nullptr, 0);
124 out.
assign(nLength, L
'\n');
125 MultiByteToWideChar(CP_UTF8, 0, utf8.data(),
static_cast<int>(utf8.size()), out.data(), nLength);
129 QX_PUSH_SUPPRESS_ALL_WARNINGS();
130 std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
131 out = converter.from_bytes(utf8.data(), utf8.data() + utf8.size());
132 QX_POP_SUPPRESS_WARNINGS();
136 #error Unsupported char type
150 template<
class char_t,
size_t N>
151 constexpr std::array<char_t, N> to_char_array(std::span<const char, N> svChar)
153 std::array<char_t, N> result;
154 for (
size_t i = 0; i < N; ++i)
155 result[i] = svChar[i];
159 template<
class char_t,
string_literal array>
162 static constexpr
auto char_array =
163 to_char_array<char_t>(std::span<
const char, array.size()>(array.data(), array.data() + array.size()));
168 template<
class char_t,
string_literal array>
172 return basic_string_view<char_t>(chars.data(), chars.size() - 1);
#define QX_SET_FILE_CATEGORY(_category)
Set the file category You can access this value via QX_GET_FILE_CATEGORY() This category will not be ...
void assign(size_type nSymbols, value_type chSymbol) noexcept
Assign by filling.
constexpr basic_string_view< char_t > convert_string_literal()
Convert a constexpr string literal to the wider or equal char type string view.
void to_wstring(wstring &out, cstring_view stringView, const std::locale &locale=std::locale())
convert cstring to wstring
void to_string(string &out, cstring_view stringView, const std::locale &locale=std::locale())
Convert a char string to common string type.
void utf8_to_string(string &out, cstring_view pszUtf8)
Convert const char* representing UTF8 to wstring.
void to_cstring(cstring &out, wstring_view stringView, const std::locale &locale=std::locale())
Convert wstring to cstring.