16 inline auto& get_locale_state()
20 #if QX_STRING_USE_CRT_LOCALE
21 struct crt_locale_deleter
23 void operator()(_locale_t locale)
const noexcept
30 using crt_locale_ptr = std::unique_ptr<std::remove_pointer_t<_locale_t>, crt_locale_deleter>;
38 void set(
const std::locale& value)
40 #if QX_STRING_USE_CRT_LOCALE
47 const std::string sName = value.name();
48 crt_locale_ptr crtValue;
49 if (sName !=
"*" && sName !=
"C")
50 crtValue.reset(_create_locale(LC_CTYPE, sName.c_str()));
53 facet = &std::use_facet<std::ctype<wchar_t>>(locale);
54 #if QX_STRING_USE_CRT_LOCALE
55 crtLocale = std::move(crtValue);
59 std::locale locale = std::locale();
60 const std::ctype<wchar_t>* facet = &std::use_facet<std::ctype<wchar_t>>(locale);
61 #if QX_STRING_USE_CRT_LOCALE
62 crt_locale_ptr crtLocale;
66 static locale_state s_State;
74 details::get_locale_state().set(locale);
79 return details::get_locale_state().locale;
84 return *details::get_locale_state().facet;
const std::locale & get_locale()
Get the default locale used by string converters.
const std::ctype< wchar_t > & get_locale_facet()
Get the cached character conversion facet for the default locale.
void set_locale(const std::locale &locale)
Set the locale used by string converters by default.