📄 locale_facets.tcc
字号:
_S_pad_numeric(_OutIter __s, ios_base::fmtflags __flags, _CharT __fill, int __width, _CharT const* __first, _CharT const* __middle, _CharT const* __last) { int __padding = __width - (__last - __first); if (__padding < 0) __padding = 0; ios_base::fmtflags __aflags = __flags & ios_base::adjustfield; bool __testfield = __padding == 0 || __aflags == ios_base::left || __aflags == ios_base::internal; // This was needlessly complicated. if (__first != __middle) { if (!__testfield) { _S_fill(__s, __fill, __padding); __padding = 0; } copy(__first, __middle, __s); } _OutIter __s2 = __s; if (__padding && __aflags != ios_base::left) { _S_fill(__s2, __fill, __padding); __padding = 0; } _OutIter __s3 = copy(__middle, __last, __s2); if (__padding) _S_fill(__s3, __fill, __padding); return __s3; } template <typename _CharT, typename _OutIter> _OutIter num_put<_CharT, _OutIter>:: do_put(iter_type __s, ios_base& __io, char_type __fill, bool __v) const { const _Format_cache<_CharT>* __fmt = _Format_cache<_CharT>::_S_get(__io); ios_base::fmtflags __flags = __io.flags(); if ((__flags & ios_base::boolalpha) == 0) this->do_put(__s, __io, __fill, static_cast<unsigned long>(__v)); else { const char_type* __first; const char_type* __last; if (__v) { __first = __fmt->_M_truename.data(); __last = __first + __fmt->_M_truename.size(); } else { __first = __fmt->_M_falsename.data(); __last = __first + __fmt->_M_falsename.size(); } copy(__first, __last, __s); } return __s; } // _S_group_digits inserts "group separator" characters into an array // of characters. It's recursive, one iteration per group. It moves // the characters in the buffer this way: "xxxx12345" -> "12,345xxx". // Call this only with __grouping != __grend. template <typename _CharT> _CharT* _S_group_digits(_CharT* __s, _CharT __grsep, char const* __grouping, char const* __grend, _CharT const* __first, _CharT const* __last) { if (__last - __first > *__grouping) { __s = _S_group_digits(__s, __grsep, (__grouping + 1 == __grend ? __grouping : __grouping + 1), __grend, __first, __last - *__grouping); __first = __last - *__grouping; *__s++ = __grsep; } do { *__s++ = *__first++; } while (__first != __last); return __s; } template <typename _CharT, typename _OutIter> _OutIter _S_format_long(_OutIter __s, ios_base& __io, _CharT __fill, bool __neg, unsigned long __v) { // Leave room for "-0x" and commas. const long _M_room = numeric_limits<unsigned long>::digits10 * 2 + 4; _CharT __digits[_M_room]; _CharT* __front = __digits + _M_room; ios_base::fmtflags __flags = __io.flags(); const _Format_cache<_CharT>* __fmt = _Format_cache<_CharT>::_S_get(__io); char const* __table = __fmt->_S_literals + __fmt->_S_digits; ios_base::fmtflags __basefield = (__flags & __io.basefield); _CharT* __sign_end = __front; if (__basefield == __io.hex) { if (__flags & ios_base::uppercase) __table += 16; // use ABCDEF do { *--__front = __table[__v & 15]; } while ((__v >>= 4) != 0); __sign_end = __front; if (__flags & __io.showbase) { *--__front = __fmt->_S_literals[__fmt->_S_ecks + ((__flags & ios_base::uppercase) ? 1 : 0)]; *--__front = __table[0]; } } else if (__basefield == __io.oct) { do { *--__front = __table[__v & 7]; } while ((__v >>= 3) != 0); if (__flags & __io.showbase && *__front != __table[0]) *--__front = __table[0]; __sign_end = __front; } else { // note: this is _lots_ faster than using ldiv. do { *--__front = __table[__v % 10]; } while ((__v /= 10) != 0); __sign_end = __front; } if (__neg || (__flags & __io.showpos)) *--__front = __fmt->_S_literals[__fmt->_S_plus - __neg]; if (!__fmt->_M_use_grouping && !__io.width()) return copy(__front, __digits+_M_room, __s); // XXX should specialize! if (!__fmt->_M_use_grouping) return _S_pad_numeric(__s, __flags, __fill, __io.width(0), __front, __sign_end, __digits + _M_room); _CharT* __p = __digits; while (__front < __sign_end) *__p++ = *__front++; const char* __gr = __fmt->_M_grouping.data(); __front = _S_group_digits(__p, __fmt->_M_thousands_sep, __gr, __gr + __fmt->_M_grouping.size(), __sign_end, __digits + _M_room); return _S_pad_numeric(__s, __flags, __fill, __io.width(0), __digits, __p, __front); } template <typename _CharT, typename _OutIter> _OutIter num_put<_CharT, _OutIter>:: do_put(iter_type __s, ios_base& __io, char_type __fill, long __v) const { unsigned long __uv = __v; bool __neg = false; if (__v < 0) { __neg = true; __uv = -__uv; } return _S_format_long(__s, __io, __fill, __neg, __uv); }#ifdef _GLIBCPP_USE_LONG_LONG template <typename _CharT, typename _OutIter> _OutIter num_put<_CharT, _OutIter>:: do_put(iter_type __s, ios_base& __b, char_type __fill, long long __v) const { unsigned long long __uv = __v; bool __neg = false; if (__v < 0) { __neg = true; __uv = -__uv; } return _S_format_long(__s, __b, __fill, __neg, __uv); }#endif template <typename _CharT, typename _OutIter> _OutIter num_put<_CharT, _OutIter>:: do_put(iter_type __s, ios_base& __io, char_type __fill, unsigned long __v) const { return _S_format_long(__s, __io, __fill, false, __v); } template <typename _CharT, typename _OutIter> _OutIter num_put<_CharT, _OutIter>:: do_put(iter_type __s, ios_base& /*__io*/, char_type /*__fill*/, double /*__v*/) const { return __s; // XXX not done } template <typename _CharT, typename _OutIter> _OutIter num_put<_CharT, _OutIter>:: do_put(iter_type __s, ios_base& /*__io*/, char_type /*__fill*/, long double /*__v*/) const { return __s; // XXX not done } template <typename _CharT, typename _OutIter> _OutIter num_put<_CharT, _OutIter>:: do_put(iter_type __s, ios_base& __io, char_type __fill, const void* __v) const { ios_base::fmtflags __oldflags = __io.flags(__io.flags() & ~(__io.showpos|__io.basefield|__io.uppercase|__io.internal) | (__io.hex|__io.showbase)); try { _OutIter __s2 = _S_format_long(__s, __io, __fill, false, reinterpret_cast<unsigned long>(__v)); __io.flags(__oldflags); return __s2; } catch (...) { __io.flags(__oldflags); throw; } } template<typename _CharT> locale::id numpunct<_CharT>::id; template<typename _CharT> locale::id collate<_CharT>::id; // Support for time_get: // Note that these partial specializations could, and maybe should, // be changed to full specializations (by eliminating the _Dummy // argument) and moved to a .cc file. template<typename _CharT, typename _Dummy = int> struct _Weekdaynames; template<typename _Dummy> struct _Weekdaynames<char, _Dummy> { static const char* const _S_names[14]; }; template<typename _Dummy> const char* const _Weekdaynames<char,_Dummy>::_S_names[14] = { "Sun", "Sunday", "Mon", "Monday", "Tue", "Tuesday", "Wed", "Wednesday", "Thu", "Thursday", "Fri", "Friday", "Sat", "Saturday" };#ifdef _GLIBCPP_USE_WCHAR_T template<typename _Dummy> struct _Weekdaynames<wchar_t,_Dummy> { static const wchar_t* const _S_names[14]; }; template<typename _Dummy> const wchar_t* const _Weekdaynames<wchar_t,_Dummy>::_S_names[14] = { L"Sun", L"Sunday", L"Mon", L"Monday", L"Tue", L"Tuesday", L"Wed", L"Wednesday", L"Thu", L"Thursday", L"Fri", L"Friday", L"Sat", L"Saturday" };#endif template<typename _CharT, typename _Dummy = int> struct _Monthnames; template<typename _Dummy> struct _Monthnames<char,_Dummy> { static const char* const _S_names[24]; }; template<typename _Dummy> const char* const _Monthnames<char,_Dummy>::_S_names[24] = { "Jan", "January", "Feb", "February", "Mar", "March", "Apr", "April", "May", "May", "Jun", "June", "Jul", "July", "Aug", "August", "Sep", "September", "Oct", "October", "Nov", "November", "Dec", "December" };#ifdef _GLIBCPP_USE_WCHAR_T template<typename _Dummy> struct _Monthnames<wchar_t, _Dummy> { static const wchar_t* const _S_names[24]; }; template<typename _Dummy> const wchar_t* const _Monthnames<wchar_t,_Dummy>::_S_names[24] = { L"Jan", L"January", L"Feb", L"February", L"Mar", L"March", L"Apr", L"April", L"May", L"May", L"Jun", L"June", L"Jul", L"July", L"Aug", L"August", L"Sep", L"September", L"Oct", L"October", L"Nov", L"November", L"Dec", L"December" };#endif template<typename _CharT, typename _InIter> locale::id time_get<_CharT, _InIter>::id; template<typename _CharT, typename _InIter> _InIter time_get<_CharT, _InIter>:: do_get_weekday(iter_type __s, iter_type __end, ios_base& __io, ios_base::iostate& __err, tm* __t) const { if (!_M_daynames) { _M_daynames = new basic_string<_CharT>[14]; for (int __i = 0; __i < 14; ++__i) _M_daynames[__i] = _Weekdaynames<_CharT>::_S_names[__i]; } bool __at_eof = false; int __remain = 0; int __matches[14]; iter_type __out = __match_parallel(__s, __end, 14, _M_daynames, __matches, __remain, __at_eof); __err = ios_base::iostate(0); if (__at_eof) __err |= __io.eofbit; if (__remain == 1 || __remain == 2 && (__matches[0]>>1) == (__matches[1]>>1)) __t->tm_wday = (__matches[0]>>1); else __err |= __io.failbit; return __out; } template<typename _CharT, typename _InIter> _InIter time_get<_CharT, _InIter>:: do_get_monthname(iter_type __s, iter_type __end, ios_base& __io, ios_base::iostate& __err, tm* __t) const { if (!_M_monthnames) { _M_monthnames = new basic_string<_CharT>[24]; for (int __i = 0; __i < 24; ++__i) _M_monthnames[__i] = _Monthnames<_CharT>::_S_names[__i]; } bool __at_eof = false; int __remain = 0; int __matches[24]; iter_type __out = __match_parallel( __s, __end, 24, _M_monthnames, __matches, __remain, __at_eof); __err = ios_base::iostate(0); if (__at_eof) __err |= __io.eofbit; if (__remain == 1 || __remain == 2 && (__matches[0]>>1) == (__matches[1]>>1)) __t->tm_mon = (__matches[0]>>1); else __err |= __io.failbit; return __out; } template<typename _CharT, typename _OutIter> locale::id time_put<_CharT, _OutIter>::id; template<typename _CharT, typename _InIter> locale::id money_get<_CharT, _InIter>::id; template<typename _CharT, typename _OutIter> locale::id money_put<_CharT, _OutIter>::id; template<typename _CharT, bool _Intl> locale::id moneypunct<_CharT,_Intl>::id; template<typename _CharT> locale::id messages<_CharT>::id; template<> inline const ctype<char>& use_facet<const ctype<char> > (const locale& __loc) { size_t __i = ctype<char>::id._M_index; const locale::_Impl* __tmp = __loc._M_impl; return static_cast<const ctype<char>&>(* (*(__tmp->_M_facets))[__i]); }#ifdef _GLIBCPP_USE_WCHAR_T template<> inline const ctype<wchar_t>& use_facet< const ctype<wchar_t> > (const locale& __loc) { size_t __i = ctype<wchar_t>::id._M_index; const locale::_Impl* __tmp = __loc._M_impl; return static_cast<const ctype<wchar_t>&>(* (*(__tmp->_M_facets))[__i]); }#endif} // std::#endif /* _CPP_BITS_LOCFACETS_TCC */// Local Variables:// mode:c++// End:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -