diff options
author | dim <dim@FreeBSD.org> | 2013-04-27 22:47:52 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2013-04-27 22:47:52 +0000 |
commit | 815a6cc1e325a4e8596b91756039a7d699471b11 (patch) | |
tree | e5a6a26d0973c6968273f6fabb61cb3d624be555 /contrib/libc++/include/locale | |
parent | 1497a98f71419ff66d08ad2b8c90530e65521ac2 (diff) | |
download | FreeBSD-src-815a6cc1e325a4e8596b91756039a7d699471b11.zip FreeBSD-src-815a6cc1e325a4e8596b91756039a7d699471b11.tar.gz |
Merge libc++ trunk r180598. Contains several minor cleanups and bug
fixes, no major changes.
MFC after: 2 weeks
Diffstat (limited to 'contrib/libc++/include/locale')
-rw-r--r-- | contrib/libc++/include/locale | 219 |
1 files changed, 174 insertions, 45 deletions
diff --git a/contrib/libc++/include/locale b/contrib/libc++/include/locale index 9189375..49f9c08 100644 --- a/contrib/libc++/include/locale +++ b/contrib/libc++/include/locale @@ -181,18 +181,18 @@ template <class charT> class messages_byname; #include <streambuf> #include <iterator> #include <limits> -#if !__APPLE__ +#ifndef __APPLE__ #include <cstdarg> #endif #include <cstdlib> #include <ctime> -#if _WIN32 +#ifdef _WIN32 #include <support/win32/locale_win32.h> #else // _WIN32 #include <nl_types.h> #endif // !_WIN32 -#if __APPLE__ +#ifdef __APPLE__ #include <Availability.h> #endif @@ -204,7 +204,7 @@ template <class charT> class messages_byname; _LIBCPP_BEGIN_NAMESPACE_STD -#if __APPLE__ || __FreeBSD__ +#if defined(__APPLE__) || defined(__FreeBSD__) # define _LIBCPP_GET_C_LOCALE 0 #else # define _LIBCPP_GET_C_LOCALE __cloc() @@ -222,7 +222,7 @@ typedef _VSTD::unique_ptr<__locale_struct, decltype(&uselocale)> __locale_raii; // OSX has nice foo_l() functions that let you turn off use of the global // locale. Linux, not so much. The following functions avoid the locale when // that's possible and otherwise do the wrong thing. FIXME. -#ifdef __linux__ +#if defined(__linux__) || defined(EMSCRIPTEN) #ifdef _LIBCPP_LOCALE__L_EXTENSIONS decltype(MB_CUR_MAX_L(_VSTD::declval<locale_t>())) @@ -634,8 +634,7 @@ __num_get<_CharT>::__stage2_int_loop(_CharT __ct, int __base, char* __a, char*& } return -1; } - if (__a_end-__a < __num_get_buf_sz - 1) - *__a_end++ = __src[__f]; + *__a_end++ = __src[__f]; ++__dc; return 0; } @@ -673,23 +672,26 @@ __num_get<_CharT>::__stage2_float_loop(_CharT __ct, bool& __in_units, char& __ex char __x = __src[__f]; if (__x == '-' || __x == '+') { - if (__a_end == __a || (__a_end[-1] & 0xDF) == __exp) + if (__a_end == __a || (__a_end[-1] & 0x5F) == (__exp & 0x7F)) { *__a_end++ = __x; return 0; } return -1; } - if (__a_end-__a < __num_get_buf_sz - 1) - *__a_end++ = __x; if (__x == 'x' || __x == 'X') __exp = 'P'; - else if ((__x & 0xDF) == __exp) + else if ((__x & 0x5F) == __exp) { - __in_units = false; - if (__grouping.size() != 0 && __g_end-__g < __num_get_buf_sz) - *__g_end++ = __dc; + __exp |= 0x80; + if (__in_units) + { + __in_units = false; + if (__grouping.size() != 0 && __g_end-__g < __num_get_buf_sz) + *__g_end++ = __dc; + } } + *__a_end++ = __x; if (__f >= 22) return 0; ++__dc; @@ -700,7 +702,7 @@ _LIBCPP_EXTERN_TEMPLATE(struct __num_get<char>) _LIBCPP_EXTERN_TEMPLATE(struct __num_get<wchar_t>) template <class _CharT, class _InputIterator = istreambuf_iterator<_CharT> > -class _LIBCPP_VISIBLE num_get +class _LIBCPP_TYPE_VIS num_get : public locale::facet, private __num_get<_CharT> { @@ -900,13 +902,20 @@ __num_get_float(const char* __a, const char* __a_end, ios_base::iostate& __err) { if (__a != __a_end) { + typename remove_reference<decltype(errno)>::type __save_errno = errno; + errno = 0; char *__p2; long double __ld = strtold_l(__a, &__p2, _LIBCPP_GET_C_LOCALE); + typename remove_reference<decltype(errno)>::type __current_errno = errno; + if (__current_errno == 0) + errno = __save_errno; if (__p2 != __a_end) { __err = ios_base::failbit; return 0; } + else if (__current_errno == ERANGE) + __err = ios_base::failbit; return static_cast<_Tp>(__ld); } __err = ios_base::failbit; @@ -962,16 +971,28 @@ num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, char_type __atoms[26]; char_type __thousands_sep; string __grouping = this->__stage2_int_prep(__iob, __atoms, __thousands_sep); - char __a[__num_get_base::__num_get_buf_sz] = {0}; + string __buf; + __buf.resize(__buf.capacity()); + char* __a = &__buf[0]; char* __a_end = __a; unsigned __g[__num_get_base::__num_get_buf_sz]; unsigned* __g_end = __g; unsigned __dc = 0; for (; __b != __e; ++__b) + { + if (__a_end - __a == __buf.size()) + { + size_t __tmp = __buf.size(); + __buf.resize(2*__buf.size()); + __buf.resize(__buf.capacity()); + __a = &__buf[0]; + __a_end = __a + __tmp; + } if (this->__stage2_int_loop(*__b, __base, __a, __a_end, __dc, __thousands_sep, __grouping, __g, __g_end, __atoms)) break; + } if (__grouping.size() != 0 && __g_end-__g < __num_get_base::__num_get_buf_sz) *__g_end++ = __dc; // Stage 3 @@ -997,16 +1018,28 @@ num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, char_type __atoms[26]; char_type __thousands_sep; string __grouping = this->__stage2_int_prep(__iob, __atoms, __thousands_sep); - char __a[__num_get_base::__num_get_buf_sz] = {0}; + string __buf; + __buf.resize(__buf.capacity()); + char* __a = &__buf[0]; char* __a_end = __a; unsigned __g[__num_get_base::__num_get_buf_sz]; unsigned* __g_end = __g; unsigned __dc = 0; for (; __b != __e; ++__b) + { + if (__a_end - __a == __buf.size()) + { + size_t __tmp = __buf.size(); + __buf.resize(2*__buf.size()); + __buf.resize(__buf.capacity()); + __a = &__buf[0]; + __a_end = __a + __tmp; + } if (this->__stage2_int_loop(*__b, __base, __a, __a_end, __dc, __thousands_sep, __grouping, __g, __g_end, __atoms)) break; + } if (__grouping.size() != 0 && __g_end-__g < __num_get_base::__num_get_buf_sz) *__g_end++ = __dc; // Stage 3 @@ -1032,16 +1065,28 @@ num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, char_type __atoms[26]; char_type __thousands_sep; string __grouping = this->__stage2_int_prep(__iob, __atoms, __thousands_sep); - char __a[__num_get_base::__num_get_buf_sz] = {0}; + string __buf; + __buf.resize(__buf.capacity()); + char* __a = &__buf[0]; char* __a_end = __a; unsigned __g[__num_get_base::__num_get_buf_sz]; unsigned* __g_end = __g; unsigned __dc = 0; for (; __b != __e; ++__b) + { + if (__a_end - __a == __buf.size()) + { + size_t __tmp = __buf.size(); + __buf.resize(2*__buf.size()); + __buf.resize(__buf.capacity()); + __a = &__buf[0]; + __a_end = __a + __tmp; + } if (this->__stage2_int_loop(*__b, __base, __a, __a_end, __dc, __thousands_sep, __grouping, __g, __g_end, __atoms)) break; + } if (__grouping.size() != 0 && __g_end-__g < __num_get_base::__num_get_buf_sz) *__g_end++ = __dc; // Stage 3 @@ -1067,16 +1112,28 @@ num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, char_type __atoms[26]; char_type __thousands_sep; string __grouping = this->__stage2_int_prep(__iob, __atoms, __thousands_sep); - char __a[__num_get_base::__num_get_buf_sz] = {0}; + string __buf; + __buf.resize(__buf.capacity()); + char* __a = &__buf[0]; char* __a_end = __a; unsigned __g[__num_get_base::__num_get_buf_sz]; unsigned* __g_end = __g; unsigned __dc = 0; for (; __b != __e; ++__b) + { + if (__a_end - __a == __buf.size()) + { + size_t __tmp = __buf.size(); + __buf.resize(2*__buf.size()); + __buf.resize(__buf.capacity()); + __a = &__buf[0]; + __a_end = __a + __tmp; + } if (this->__stage2_int_loop(*__b, __base, __a, __a_end, __dc, __thousands_sep, __grouping, __g, __g_end, __atoms)) break; + } if (__grouping.size() != 0 && __g_end-__g < __num_get_base::__num_get_buf_sz) *__g_end++ = __dc; // Stage 3 @@ -1102,16 +1159,28 @@ num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, char_type __atoms[26]; char_type __thousands_sep; string __grouping = this->__stage2_int_prep(__iob, __atoms, __thousands_sep); - char __a[__num_get_base::__num_get_buf_sz] = {0}; + string __buf; + __buf.resize(__buf.capacity()); + char* __a = &__buf[0]; char* __a_end = __a; unsigned __g[__num_get_base::__num_get_buf_sz]; unsigned* __g_end = __g; unsigned __dc = 0; for (; __b != __e; ++__b) + { + if (__a_end - __a == __buf.size()) + { + size_t __tmp = __buf.size(); + __buf.resize(2*__buf.size()); + __buf.resize(__buf.capacity()); + __a = &__buf[0]; + __a_end = __a + __tmp; + } if (this->__stage2_int_loop(*__b, __base, __a, __a_end, __dc, __thousands_sep, __grouping, __g, __g_end, __atoms)) break; + } if (__grouping.size() != 0 && __g_end-__g < __num_get_base::__num_get_buf_sz) *__g_end++ = __dc; // Stage 3 @@ -1137,16 +1206,28 @@ num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, char_type __atoms[26]; char_type __thousands_sep; string __grouping = this->__stage2_int_prep(__iob, __atoms, __thousands_sep); - char __a[__num_get_base::__num_get_buf_sz] = {0}; + string __buf; + __buf.resize(__buf.capacity()); + char* __a = &__buf[0]; char* __a_end = __a; unsigned __g[__num_get_base::__num_get_buf_sz]; unsigned* __g_end = __g; unsigned __dc = 0; for (; __b != __e; ++__b) + { + if (__a_end - __a == __buf.size()) + { + size_t __tmp = __buf.size(); + __buf.resize(2*__buf.size()); + __buf.resize(__buf.capacity()); + __a = &__buf[0]; + __a_end = __a + __tmp; + } if (this->__stage2_int_loop(*__b, __base, __a, __a_end, __dc, __thousands_sep, __grouping, __g, __g_end, __atoms)) break; + } if (__grouping.size() != 0 && __g_end-__g < __num_get_base::__num_get_buf_sz) *__g_end++ = __dc; // Stage 3 @@ -1174,7 +1255,9 @@ num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, string __grouping = this->__stage2_float_prep(__iob, __atoms, __decimal_point, __thousands_sep); - char __a[__num_get_base::__num_get_buf_sz] = {0}; + string __buf; + __buf.resize(__buf.capacity()); + char* __a = &__buf[0]; char* __a_end = __a; unsigned __g[__num_get_base::__num_get_buf_sz]; unsigned* __g_end = __g; @@ -1182,11 +1265,21 @@ num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, bool __in_units = true; char __exp = 'E'; for (; __b != __e; ++__b) + { + if (__a_end - __a == __buf.size()) + { + size_t __tmp = __buf.size(); + __buf.resize(2*__buf.size()); + __buf.resize(__buf.capacity()); + __a = &__buf[0]; + __a_end = __a + __tmp; + } if (this->__stage2_float_loop(*__b, __in_units, __exp, __a, __a_end, __decimal_point, __thousands_sep, __grouping, __g, __g_end, __dc, __atoms)) break; + } if (__grouping.size() != 0 && __in_units && __g_end-__g < __num_get_base::__num_get_buf_sz) *__g_end++ = __dc; // Stage 3 @@ -1214,7 +1307,9 @@ num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, string __grouping = this->__stage2_float_prep(__iob, __atoms, __decimal_point, __thousands_sep); - char __a[__num_get_base::__num_get_buf_sz] = {0}; + string __buf; + __buf.resize(__buf.capacity()); + char* __a = &__buf[0]; char* __a_end = __a; unsigned __g[__num_get_base::__num_get_buf_sz]; unsigned* __g_end = __g; @@ -1222,11 +1317,21 @@ num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, bool __in_units = true; char __exp = 'E'; for (; __b != __e; ++__b) + { + if (__a_end - __a == __buf.size()) + { + size_t __tmp = __buf.size(); + __buf.resize(2*__buf.size()); + __buf.resize(__buf.capacity()); + __a = &__buf[0]; + __a_end = __a + __tmp; + } if (this->__stage2_float_loop(*__b, __in_units, __exp, __a, __a_end, __decimal_point, __thousands_sep, __grouping, __g, __g_end, __dc, __atoms)) break; + } if (__grouping.size() != 0 && __in_units && __g_end-__g < __num_get_base::__num_get_buf_sz) *__g_end++ = __dc; // Stage 3 @@ -1254,7 +1359,9 @@ num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, string __grouping = this->__stage2_float_prep(__iob, __atoms, __decimal_point, __thousands_sep); - char __a[__num_get_base::__num_get_buf_sz] = {0}; + string __buf; + __buf.resize(__buf.capacity()); + char* __a = &__buf[0]; char* __a_end = __a; unsigned __g[__num_get_base::__num_get_buf_sz]; unsigned* __g_end = __g; @@ -1262,11 +1369,21 @@ num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, bool __in_units = true; char __exp = 'E'; for (; __b != __e; ++__b) + { + if (__a_end - __a == __buf.size()) + { + size_t __tmp = __buf.size(); + __buf.resize(2*__buf.size()); + __buf.resize(__buf.capacity()); + __a = &__buf[0]; + __a_end = __a + __tmp; + } if (this->__stage2_float_loop(*__b, __in_units, __exp, __a, __a_end, __decimal_point, __thousands_sep, __grouping, __g, __g_end, __dc, __atoms)) break; + } if (__grouping.size() != 0 && __in_units && __g_end-__g < __num_get_base::__num_get_buf_sz) *__g_end++ = __dc; // Stage 3 @@ -1294,16 +1411,28 @@ num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, string __grouping; use_facet<ctype<_CharT> >(__iob.getloc()).widen(__num_get_base::__src, __num_get_base::__src + 26, __atoms); - char __a[__num_get_base::__num_get_buf_sz] = {0}; + string __buf; + __buf.resize(__buf.capacity()); + char* __a = &__buf[0]; char* __a_end = __a; unsigned __g[__num_get_base::__num_get_buf_sz]; unsigned* __g_end = __g; unsigned __dc = 0; for (; __b != __e; ++__b) + { + if (__a_end - __a == __buf.size()) + { + size_t __tmp = __buf.size(); + __buf.resize(2*__buf.size()); + __buf.resize(__buf.capacity()); + __a = &__buf[0]; + __a_end = __a + __tmp; + } if (this->__stage2_int_loop(*__b, __base, __a, __a_end, __dc, __thousands_sep, __grouping, __g, __g_end, __atoms)) break; + } // Stage 3 __a[sizeof(__a)-1] = 0; #ifdef _LIBCPP_LOCALE__L_EXTENSIONS @@ -1472,7 +1601,7 @@ _LIBCPP_EXTERN_TEMPLATE(struct __num_put<char>) _LIBCPP_EXTERN_TEMPLATE(struct __num_put<wchar_t>) template <class _CharT, class _OutputIterator = ostreambuf_iterator<_CharT> > -class _LIBCPP_VISIBLE num_put +class _LIBCPP_TYPE_VIS num_put : public locale::facet, private __num_put<_CharT> { @@ -1984,7 +2113,7 @@ __get_up_to_n_digits(_InputIterator& __b, _InputIterator __e, return __r; } -class _LIBCPP_VISIBLE time_base +class _LIBCPP_TYPE_VIS time_base { public: enum dateorder {no_order, dmy, mdy, ymd, ydm}; @@ -2006,7 +2135,7 @@ protected: }; template <class _CharT, class _InputIterator = istreambuf_iterator<_CharT> > -class _LIBCPP_VISIBLE time_get +class _LIBCPP_TYPE_VIS time_get : public locale::facet, public time_base, private __time_get_c_storage<_CharT> @@ -2656,7 +2785,7 @@ private: }; template <class _CharT, class _InputIterator = istreambuf_iterator<_CharT> > -class _LIBCPP_VISIBLE time_get_byname +class _LIBCPP_TYPE_VIS time_get_byname : public time_get<_CharT, _InputIterator>, private __time_get_storage<_CharT> { @@ -2716,7 +2845,7 @@ protected: }; template <class _CharT, class _OutputIterator = ostreambuf_iterator<_CharT> > -class _LIBCPP_VISIBLE time_put +class _LIBCPP_TYPE_VIS time_put : public locale::facet, private __time_put { @@ -2815,7 +2944,7 @@ _LIBCPP_EXTERN_TEMPLATE(class time_put<char>) _LIBCPP_EXTERN_TEMPLATE(class time_put<wchar_t>) template <class _CharT, class _OutputIterator = ostreambuf_iterator<_CharT> > -class _LIBCPP_VISIBLE time_put_byname +class _LIBCPP_TYPE_VIS time_put_byname : public time_put<_CharT, _OutputIterator> { public: @@ -2837,7 +2966,7 @@ _LIBCPP_EXTERN_TEMPLATE(class time_put_byname<wchar_t>) // money_base -class _LIBCPP_VISIBLE money_base +class _LIBCPP_TYPE_VIS money_base { public: enum part {none, space, symbol, sign, value}; @@ -2849,7 +2978,7 @@ public: // moneypunct template <class _CharT, bool _International = false> -class _LIBCPP_VISIBLE moneypunct +class _LIBCPP_TYPE_VIS moneypunct : public locale::facet, public money_base { @@ -2907,7 +3036,7 @@ _LIBCPP_EXTERN_TEMPLATE(class moneypunct<wchar_t, true>) // moneypunct_byname template <class _CharT, bool _International = false> -class _LIBCPP_VISIBLE moneypunct_byname +class _LIBCPP_TYPE_VIS moneypunct_byname : public moneypunct<_CharT, _International> { public: @@ -3019,7 +3148,7 @@ _LIBCPP_EXTERN_TEMPLATE(class __money_get<char>) _LIBCPP_EXTERN_TEMPLATE(class __money_get<wchar_t>) template <class _CharT, class _InputIterator = istreambuf_iterator<_CharT> > -class _LIBCPP_VISIBLE money_get +class _LIBCPP_TYPE_VIS money_get : public locale::facet, private __money_get<_CharT> { @@ -3353,7 +3482,7 @@ money_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, if (__neg) *__nc++ = '-'; for (const char_type* __w = __wb.get(); __w < __wn; ++__w, ++__nc) - *__nc = __src[find(__atoms, __atoms+sizeof(__atoms), *__w) - __atoms]; + *__nc = __src[find(__atoms, _VSTD::end(__atoms), *__w) - __atoms]; *__nc = char(); if (sscanf(__nbuf, "%Lf", &__v) != 1) __throw_runtime_error("money_get error"); @@ -3575,7 +3704,7 @@ _LIBCPP_EXTERN_TEMPLATE(class __money_put<char>) _LIBCPP_EXTERN_TEMPLATE(class __money_put<wchar_t>) template <class _CharT, class _OutputIterator = ostreambuf_iterator<_CharT> > -class _LIBCPP_VISIBLE money_put +class _LIBCPP_TYPE_VIS money_put : public locale::facet, private __money_put<_CharT> { @@ -3733,7 +3862,7 @@ _LIBCPP_EXTERN_TEMPLATE(class money_put<wchar_t>) // messages -class _LIBCPP_VISIBLE messages_base +class _LIBCPP_TYPE_VIS messages_base { public: typedef ptrdiff_t catalog; @@ -3742,7 +3871,7 @@ public: }; template <class _CharT> -class _LIBCPP_VISIBLE messages +class _LIBCPP_TYPE_VIS messages : public locale::facet, public messages_base { @@ -3793,7 +3922,7 @@ template <class _CharT> typename messages<_CharT>::catalog messages<_CharT>::do_open(const basic_string<char>& __nm, const locale&) const { -#if _WIN32 +#ifdef _WIN32 return -1; #else // _WIN32 catalog __cat = (catalog)catopen(__nm.c_str(), NL_CAT_LOCALE); @@ -3808,7 +3937,7 @@ typename messages<_CharT>::string_type messages<_CharT>::do_get(catalog __c, int __set, int __msgid, const string_type& __dflt) const { -#if _WIN32 +#ifdef _WIN32 return __dflt; #else // _WIN32 string __ndflt; @@ -3830,7 +3959,7 @@ template <class _CharT> void messages<_CharT>::do_close(catalog __c) const { -#if !_WIN32 +#if !defined(_WIN32) if (__c != -1) __c <<= 1; nl_catd __cat = (nl_catd)__c; @@ -3842,7 +3971,7 @@ _LIBCPP_EXTERN_TEMPLATE(class messages<char>) _LIBCPP_EXTERN_TEMPLATE(class messages<wchar_t>) template <class _CharT> -class _LIBCPP_VISIBLE messages_byname +class _LIBCPP_TYPE_VIS messages_byname : public messages<_CharT> { public: @@ -3868,7 +3997,7 @@ _LIBCPP_EXTERN_TEMPLATE(class messages_byname<wchar_t>) template<class _Codecvt, class _Elem = wchar_t, class _Wide_alloc = allocator<_Elem>, class _Byte_alloc = allocator<char> > -class _LIBCPP_VISIBLE wstring_convert +class _LIBCPP_TYPE_VIS wstring_convert { public: typedef basic_string<char, char_traits<char>, _Byte_alloc> byte_string; @@ -4121,7 +4250,7 @@ wstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>:: } template <class _Codecvt, class _Elem = wchar_t, class _Tr = char_traits<_Elem> > -class _LIBCPP_VISIBLE wbuffer_convert +class _LIBCPP_TYPE_VIS wbuffer_convert : public basic_streambuf<_Elem, _Tr> { public: |