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
124 if (!std::in_range<int>(utf8.size()))
130 const int nInputLength =
static_cast<int>(utf8.size());
131 const int nLength = MultiByteToWideChar(CP_UTF8, 0, utf8.data(), nInputLength,
nullptr, 0);
132 out.
assign(nLength, L
'\n');
133 MultiByteToWideChar(CP_UTF8, 0, utf8.data(), nInputLength, out.data(), nLength);
137 QX_PUSH_SUPPRESS_ALL_WARNINGS();
138 std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
139 out = converter.from_bytes(utf8.data(), utf8.data() + utf8.size());
140 QX_POP_SUPPRESS_WARNINGS();
144 #error Unsupported char type
158 template<
class char_t,
size_t N>
159 constexpr std::array<char_t, N> to_char_array(std::span<const char, N> svChar)
161 std::array<char_t, N> result;
162 for (
size_t i = 0; i < N; ++i)
163 result[i] = svChar[i];
167 template<
class char_t,
string_literal array>
170 static constexpr
auto k_CharArray =
171 to_char_array<char_t>(std::span<
const char, array.size()>(array.data(), array.data() + array.size()));
176 template<
class char_t,
string_literal array>
180 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.