locale_facets.tcc
来自「ARM Linux Tool 各种代码包括MTD」· TCC 代码 · 共 1,228 行 · 第 1/3 页
TCC
1,228 行
return __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* __group_digits(_CharT* __s, _CharT __grsep, char const* __grouping, char const* __grend, _CharT const* __first, _CharT const* __last) { if (__last - __first > *__grouping) { __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, typename _ValueT> _OutIter __output_integer(_OutIter __s, ios_base& __io, _CharT __fill, bool __neg, _ValueT __v) { // Leave room for "+/-," "0x," and commas. const long _M_room = numeric_limits<_ValueT>::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 == ios_base::hex) { if (__flags & ios_base::uppercase) __table += 16; // use ABCDEF do *--__front = __table[__v & 15]; while ((__v >>= 4) != 0); __sign_end = __front; if (__flags & ios_base::showbase) { *--__front = __fmt->_S_literals[__fmt->_S_x + ((__flags & ios_base::uppercase) ? 1 : 0)]; *--__front = __table[0]; } } else if (__basefield == ios_base::oct) { do *--__front = __table[__v & 7]; while ((__v >>= 3) != 0); if (__flags & ios_base::showbase && static_cast<char>(*__front) != __table[0]) *--__front = __table[0]; __sign_end = __front; } else { // NB: This is _lots_ faster than using ldiv. do *--__front = __table[__v % 10]; while ((__v /= 10) != 0); __sign_end = __front; // NB: ios_base:hex || ios_base::oct assumed to be unsigned. if (__neg || (__flags & ios_base::showpos)) *--__front = __fmt->_S_literals[__fmt->_S_plus - __neg]; } // XXX should specialize! if (!__fmt->_M_use_grouping && !__io.width()) return copy(__front, __digits + _M_room, __s); if (!__fmt->_M_use_grouping) return __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 = __group_digits(__p, __fmt->_M_thousands_sep, __gr, __gr + __fmt->_M_grouping.size(), __sign_end, __digits + _M_room); return __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 __output_integer(__s, __io, __fill, __neg, __uv); } 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 __output_integer(__s, __io, __fill, false, __v); }#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 __output_integer(__s, __b, __fill, __neg, __uv); } template <typename _CharT, typename _OutIter> _OutIter num_put<_CharT, _OutIter>:: do_put(iter_type __s, ios_base& __io, char_type __fill, unsigned long long __v) const { return __output_integer(__s, __io, __fill, false, __v); }#endif // Generic helper function template<typename _CharT, typename _Traits, typename _OutIter> _OutIter __output_float(_OutIter __s, ios_base& __io, _CharT __fill, const char* __sptr, size_t __slen) { // XXX Not currently done: non streambuf_iterator return __s; } // Partial specialization for ostreambuf_iterator. template<typename _CharT, typename _Traits> ostreambuf_iterator<_CharT, _Traits> __output_float(ostreambuf_iterator<_CharT, _Traits> __s, ios_base& __io, _CharT __fill, const char* __sptr, size_t __slen) { size_t __padding = __io.width() > streamsize(__slen) ? __io.width() -__slen : 0; locale __loc = __io.getloc(); ctype<_CharT> const& __ct = use_facet<ctype<_CharT> >(__loc); ios_base::fmtflags __adjfield = __io.flags() & ios_base::adjustfield; const char* const __eptr = __sptr + __slen; // [22.2.2.2.2.19] Table 61 if (__adjfield == ios_base::internal) { // [22.2.2.2.2.14]; widen() if (__sptr < __eptr && (*__sptr == '+' || *__sptr == '-')) { __s = __ct.widen(*__sptr); ++__s; ++__sptr; } __s = __pad(__s, __fill, __padding); __padding = 0; } else if (__adjfield != ios_base::left) { __s = __pad(__s, __fill, __padding); __padding = 0; } // the "C" locale decimal character char __decimal_point = *(localeconv()->decimal_point); const _Format_cache<_CharT>* __fmt = _Format_cache<_CharT>::_S_get(__io); for (; __sptr != __eptr; ++__s, ++__sptr) { // [22.2.2.2.2.17]; decimal point conversion if (*__sptr == __decimal_point) __s = __fmt->_M_decimal_point; // [22.2.2.2.2.14]; widen() else __s = __ct.widen(*__sptr); } // [22.2.2.2.2.19] Table 61 if (__padding) __pad(__s, __fill, __padding); __io.width(0); return __s; } bool __build_float_format(ios_base& __io, char* __fptr, char __modifier, streamsize __prec); template <typename _CharT, typename _OutIter> _OutIter num_put<_CharT, _OutIter>:: do_put(iter_type __s, ios_base& __io, char_type __fill, double __v) const { const streamsize __max_prec = numeric_limits<double>::digits10 + 3; streamsize __prec = __io.precision(); // Protect against sprintf() buffer overflows. if (__prec > __max_prec) __prec = __max_prec; // The *2 provides for signs, exp, 'E', and pad. char __sbuf[__max_prec * 2]; size_t __slen; // Long enough for the max format spec. char __fbuf[16]; if (__build_float_format(__io, __fbuf, 0, __prec)) __slen = sprintf(__sbuf, __fbuf, __prec, __v); else __slen = sprintf(__sbuf, __fbuf, __v); // [22.2.2.2.2] Stages 2-4. return __output_float(__s, __io, __fill, __sbuf, __slen); } 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 { const streamsize __max_prec = numeric_limits<long double>::digits10 + 3; streamsize __prec = __io.precision(); // Protect against sprintf() buffer overflows. if (__prec > __max_prec) __prec = __max_prec; // The *2 provides for signs, exp, 'E', and pad. char __sbuf[__max_prec * 2]; size_t __slen; // Long enough for the max format spec. char __fbuf[16]; // 'L' as per [22.2.2.2.2] Table 59 if (__build_float_format(__io, __fbuf, 'L', __prec)) __slen = sprintf(__sbuf, __fbuf, __prec, __v); else __slen = sprintf(__sbuf, __fbuf, __v); // [22.2.2.2.2] Stages 2-4 return __output_float(__s, __io, __fill, __sbuf, __slen); } 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 { typedef ios_base::fmtflags fmtflags; fmtflags __fmt = __io.flags(); fmtflags __fmtmask = ~(ios_base::showpos | ios_base::basefield | ios_base::uppercase | ios_base::internal); __io.flags(__fmt & __fmtmask | (ios_base::hex | ios_base::showbase)); try { _OutIter __s2 = __output_integer(__s, __io, __fill, false, reinterpret_cast<unsigned long>(__v)); __io.flags(__fmt); return __s2; } catch (...) { __io.flags(__fmt); __throw_exception_again; } } // 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> _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; }} // std::#endif /* _CPP_BITS_LOCFACETS_TCC */// Local Variables:// mode:c++// End:
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?