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();
124 #define _GLIBCXX_STD_FACET(...) \ 125 if _GLIBCXX_CONSTEXPR (__is_same(const _Facet, const __VA_ARGS__)) \ 126 return static_cast<const _Facet*>(__facets[__i]) 142 #ifdef _GLIBCXX_USE_WCHAR_T 157 #if __cplusplus >= 201103L 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>
242 template<
typename _CharT>
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 412 const collate<wchar_t>*
413 __try_use_facet<collate<wchar_t> >(
const locale&) _GLIBCXX_NOTHROW;
416 const collate<wchar_t>&
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 bool operator()(const basic_string< _Char, _Traits, _Alloc > &__s1, const basic_string< _Char, _Traits, _Alloc > &__s2) const
Compare two strings according to collate.
virtual int do_compare(const _CharT *__lo1, const _CharT *__hi1, const _CharT *__lo2, const _CharT *__hi2) const
Compare two strings.
void push_back(_CharT __c)
Append a single character.
size_type length() const noexcept
Returns the number of characters in the string, not including any null-termination.
Primary class template time_get.This facet encapsulates the code to parse and return a date or time f...
Facet for localized string comparison.
const _CharT * data() const noexcept
Return const pointer to contents.
Primary class template num_get.This facet encapsulates the code to parse and return a number from a s...
virtual string_type do_transform(const _CharT *__lo, const _CharT *__hi) const
Transform string to comparable form.
locale()
Default constructor.
const _CharT * c_str() const noexcept
Return const pointer to null-terminated contents.
Localization functionality base class.The facet class is the base class for a localization feature...
Primary class template money_put.This facet encapsulates the code to format and output a monetary amo...
Primary class template time_put.This facet encapsulates the code to format and output dates and times...
ISO C++ entities toplevel namespace is std.
basic_string & append(const basic_string &__str)
Append a string to this string.
Container class for localization functionality.The locale class is first a class wrapper for C librar...
Primary class template num_put.This facet encapsulates the code to convert a number to a string...
Primary class template moneypunct.This facet encapsulates the punctuation, grouping and other formatt...
Class codecvt<char32_t, char, mbstate_t> specialization.
class collate_byname [22.2.4.2].
Primary class template messages.This facet encapsulates the code to retrieve messages from message ca...
Primary class template money_get.This facet encapsulates the code to parse and return a monetary amou...
The ctype<wchar_t> specialization.This class defines classification and conversion functions for the ...
class codecvt<char, char, mbstate_t> specialization.
Basis for explicit traits specializations.
The ctype<char> specialization.This class defines classification and conversion functions for the cha...
locale combine(const locale &__other) const
Construct locale with another facet.
friend const _Facet & use_facet(const locale &)
Return a facet.use_facet looks for and returns a reference to a facet of type Facet where Facet is th...
Class codecvt<char16_t, char, mbstate_t> specialization.
virtual long do_hash(const _CharT *__lo, const _CharT *__hi) const
Return hash of a string.
Managing sequences of characters and character-like objects.
friend bool has_facet(const locale &)
Test for the presence of a facet.has_facet tests the locale argument for the presence of the facet ty...
Primary class template numpunct.This facet stores several pieces of information related to printing a...
Class codecvt<wchar_t, char, mbstate_t> specialization.