34 #ifndef _LOCALE_CLASSES_TCC 35 #define _LOCALE_CLASSES_TCC 1 37 #ifdef _GLIBCXX_SYSHDR 38 #pragma GCC system_header 43 #pragma GCC diagnostic push 44 #pragma GCC diagnostic ignored "-Wc++11-extensions" // extern template 45 #pragma GCC diagnostic ignored "-Wvariadic-macros" 47 namespace std _GLIBCXX_VISIBILITY(default)
49 _GLIBCXX_BEGIN_NAMESPACE_VERSION
51 template<
typename _Facet>
57 if (__builtin_expect(!__f, 0))
59 _M_impl = __other._M_impl;
60 _M_impl->_M_add_reference();
64 _M_impl =
new _Impl(*__other._M_impl, 1);
67 { _M_impl->_M_install_facet(&_Facet::id, __f); }
70 _M_impl->_M_remove_reference();
71 __throw_exception_again;
73 delete [] _M_impl->_M_names[0];
74 _M_impl->_M_names[0] = 0;
77 template<
typename _Facet>
82 #if __cpp_lib_type_trait_variable_templates // C++ >= 17 83 static_assert(__is_facet<_Facet>,
"Template argument must be a facet");
86 _Impl* __tmp =
new _Impl(*_M_impl, 1);
89 __tmp->_M_replace_facet(__other._M_impl, &_Facet::id);
93 __tmp->_M_remove_reference();
94 __throw_exception_again;
96 delete[] __tmp->_M_names[0];
97 __tmp->_M_names[0] = 0;
101 template<
typename _CharT,
typename _Traits,
typename _Alloc>
108 const __collate_type& __collate = use_facet<__collate_type>(*this);
109 return (__collate.compare(__s1.
data(), __s1.
data() + __s1.
length(),
113 #pragma GCC diagnostic push 114 #pragma GCC diagnostic ignored "-Wc++17-extensions" 115 template<
typename _Facet>
117 __try_use_facet(
const locale& __loc) _GLIBCXX_NOTHROW
119 const size_t __i = _Facet::id._M_id();
120 const locale::facet** __facets = __loc._M_impl->_M_facets;
124 #define _GLIBCXX_STD_FACET(...) \ 125 if _GLIBCXX_CONSTEXPR (__is_same(const _Facet, const __VA_ARGS__)) \ 126 return static_cast<const _Facet*>(__facets[__i]) 128 _GLIBCXX_STD_FACET(ctype<char>);
129 _GLIBCXX_STD_FACET(num_get<char>);
130 _GLIBCXX_STD_FACET(num_put<char>);
131 _GLIBCXX_STD_FACET(codecvt<char, char, mbstate_t>);
132 _GLIBCXX_STD_FACET(collate<char>);
133 _GLIBCXX_STD_FACET(moneypunct<char>);
134 _GLIBCXX_STD_FACET(moneypunct<char, true>);
135 _GLIBCXX_STD_FACET(money_get<char>);
136 _GLIBCXX_STD_FACET(money_put<char>);
137 _GLIBCXX_STD_FACET(numpunct<char>);
138 _GLIBCXX_STD_FACET(time_get<char>);
139 _GLIBCXX_STD_FACET(time_put<char>);
140 _GLIBCXX_STD_FACET(messages<char>);
142 #ifdef _GLIBCXX_USE_WCHAR_T 143 _GLIBCXX_STD_FACET(ctype<wchar_t>);
144 _GLIBCXX_STD_FACET(num_get<wchar_t>);
145 _GLIBCXX_STD_FACET(num_put<wchar_t>);
146 _GLIBCXX_STD_FACET(codecvt<wchar_t, char, mbstate_t>);
147 _GLIBCXX_STD_FACET(collate<wchar_t>);
148 _GLIBCXX_STD_FACET(moneypunct<wchar_t>);
149 _GLIBCXX_STD_FACET(moneypunct<wchar_t, true>);
150 _GLIBCXX_STD_FACET(money_get<wchar_t>);
151 _GLIBCXX_STD_FACET(money_put<wchar_t>);
152 _GLIBCXX_STD_FACET(numpunct<wchar_t>);
153 _GLIBCXX_STD_FACET(time_get<wchar_t>);
154 _GLIBCXX_STD_FACET(time_put<wchar_t>);
155 _GLIBCXX_STD_FACET(messages<wchar_t>);
157 #if __cplusplus >= 201103L 158 _GLIBCXX_STD_FACET(codecvt<char16_t, char, mbstate_t>);
159 _GLIBCXX_STD_FACET(codecvt<char32_t, char, mbstate_t>);
162 #undef _GLIBCXX_STD_FACET 164 if (__i >= __loc._M_impl->_M_facets_size || !__facets[__i])
168 return dynamic_cast<const _Facet*
>(__facets[__i]);
170 return static_cast<const _Facet*
>(__facets[__i]);
173 #pragma GCC diagnostic pop 187 template<
typename _Facet>
192 #if __cplusplus >= 201103L 194 "template argument must be derived from locale::facet");
196 (void) static_cast<const _Facet*>(static_cast<const locale::facet*>(0));
198 return std::__try_use_facet<_Facet>(__loc) != 0;
215 #pragma GCC diagnostic push 216 #pragma GCC diagnostic ignored "-Wdangling-reference" 217 template<
typename _Facet>
222 #if __cplusplus >= 201103L 224 "template argument must be derived from locale::facet");
226 (void) static_cast<const _Facet*>(static_cast<const locale::facet*>(0));
228 if (
const _Facet* __f = std::__try_use_facet<_Facet>(__loc))
232 #pragma GCC diagnostic pop 236 template<
typename _CharT>
238 collate<_CharT>::_M_compare(
const _CharT*,
const _CharT*)
const throw ()
242 template<
typename _CharT>
244 collate<_CharT>::_M_transform(_CharT*,
const _CharT*,
size_t)
const throw ()
247 template<
typename _CharT>
251 const _CharT* __lo2,
const _CharT* __hi2)
const 258 const _CharT* __p = __one.
c_str();
259 const _CharT* __pend = __one.
data() + __one.
length();
260 const _CharT* __q = __two.
c_str();
261 const _CharT* __qend = __two.
data() + __two.
length();
268 const int __res = _M_compare(__p, __q);
274 if (__p == __pend && __q == __qend)
276 else if (__p == __pend)
278 else if (__q == __qend)
286 template<
typename _CharT>
296 const _CharT* __p = __str.
c_str();
297 const _CharT* __pend = __str.
data() + __str.
length();
299 size_t __len = (__hi - __lo) * 2;
303 _Buf(
size_t __n,
void* __buf,
int __e)
304 : _M_c(__buf ? (_CharT*)__buf :
new _CharT[__n]),
311 if (_M_c != _M_stackbuf)
317 void _M_realloc(
size_t __len)
319 _CharT* __p =
new _CharT[__len];
320 if (_M_c != _M_stackbuf)
326 void*
const _M_stackbuf;
330 const size_t __bytes = __len *
sizeof(_CharT);
331 _Buf __buf(__len, __bytes <= 256 ? __builtin_alloca(__bytes) : 0, errno);
340 size_t __res = _M_transform(__buf._M_c, __p, __len);
345 if (__builtin_expect(errno, 0))
348 __throw_system_error(errno);
359 __buf._M_realloc(__len);
360 __res = _M_transform(__buf._M_c, __p, __len);
363 __ret.
append(__buf._M_c, __res);
375 template<
typename _CharT>
378 do_hash(
const _CharT* __lo,
const _CharT* __hi)
const 380 unsigned long __val = 0;
381 for (; __lo < __hi; ++__lo)
383 *__lo + ((__val << 7)
384 | (__val >> (__gnu_cxx::__numeric_traits<unsigned long>::
386 return static_cast<long>(__val);
391 #if _GLIBCXX_EXTERN_TEMPLATE 397 __try_use_facet<collate<char> >(
const locale&) _GLIBCXX_NOTHROW;
401 use_facet<collate<char> >(
const locale&);
405 has_facet<collate<char> >(
const locale&);
407 #ifdef _GLIBCXX_USE_WCHAR_T 413 __try_use_facet<collate<wchar_t> >(
const locale&) _GLIBCXX_NOTHROW;
417 use_facet<collate<wchar_t> >(
const locale&);
421 has_facet<collate<wchar_t> >(
const locale&);
425 _GLIBCXX_END_NAMESPACE_VERSION
428 #pragma GCC diagnostic pop const _Facet & use_facet(const locale &__loc)
Return a facet.use_facet looks for and returns a reference to a facet of type Facet where Facet is th...
virtual int do_compare(const _CharT *__lo1, const _CharT *__hi1, const _CharT *__lo2, const _CharT *__hi2) const
Compare two strings.
class collate_byname [22.2.4.2].
Basis for explicit traits specializations.
const _CharT * data() const noexcept
Return const pointer to contents.
void push_back(_CharT __c)
Append a single character.
locale()
Default constructor.
locale combine(const locale &__other) const
Construct locale with another facet.
size_type length() const noexcept
Returns the number of characters in the string, not including any null-termination.
Localization functionality base class.The facet class is the base class for a localization feature...
virtual long do_hash(const _CharT *__lo, const _CharT *__hi) const
Return hash of a string.
bool operator()(const basic_string< _Char, _Traits, _Alloc > &__s1, const basic_string< _Char, _Traits, _Alloc > &__s2) const
Compare two strings according to collate.
ISO C++ entities toplevel namespace is std.
Facet for localized string comparison.
virtual string_type do_transform(const _CharT *__lo, const _CharT *__hi) const
Transform string to comparable form.
const _CharT * c_str() const noexcept
Return const pointer to null-terminated contents.
Managing sequences of characters and character-like objects.
Container class for localization functionality.The locale class is first a class wrapper for C librar...
bool has_facet(const locale &__loc) noexcept
Test for the presence of a facet.has_facet tests the locale argument for the presence of the facet ty...
basic_string & append(const basic_string &__str)
Append a string to this string.