diff options
Diffstat (limited to 'src/locale.cpp')
-rw-r--r-- | src/locale.cpp | 233 |
1 files changed, 41 insertions, 192 deletions
diff --git a/src/locale.cpp b/src/locale.cpp index 6b04e78817641..da2fd11678d60 100644 --- a/src/locale.cpp +++ b/src/locale.cpp @@ -123,11 +123,6 @@ const locale::category locale::time; const locale::category locale::messages; const locale::category locale::all; -#if defined(__clang__) -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wpadded" -#endif - class _LIBCPP_HIDDEN locale::__imp : public facet { @@ -163,10 +158,6 @@ private: template <class F> void install_from(const __imp& other); }; -#if defined(__clang__) -#pragma clang diagnostic pop -#endif - locale::__imp::__imp(size_t refs) : facet(refs), facets_(N), @@ -1409,33 +1400,21 @@ ctype_byname<wchar_t>::do_tolower(char_type* low, const char_type* high) const wchar_t ctype_byname<wchar_t>::do_widen(char c) const { -#ifdef _LIBCPP_LOCALE__L_EXTENSIONS - return btowc_l(c, __l); -#else - return __btowc_l(c, __l); -#endif + return __libcpp_btowc_l(c, __l); } const char* ctype_byname<wchar_t>::do_widen(const char* low, const char* high, char_type* dest) const { for (; low != high; ++low, ++dest) -#ifdef _LIBCPP_LOCALE__L_EXTENSIONS - *dest = btowc_l(*low, __l); -#else - *dest = __btowc_l(*low, __l); -#endif + *dest = __libcpp_btowc_l(*low, __l); return low; } char ctype_byname<wchar_t>::do_narrow(char_type c, char dfault) const { -#ifdef _LIBCPP_LOCALE__L_EXTENSIONS - int r = wctob_l(c, __l); -#else - int r = __wctob_l(c, __l); -#endif + int r = __libcpp_wctob_l(c, __l); return r != static_cast<int>(WEOF) ? static_cast<char>(r) : dfault; } @@ -1444,11 +1423,7 @@ ctype_byname<wchar_t>::do_narrow(const char_type* low, const char_type* high, ch { for (; low != high; ++low, ++dest) { -#ifdef _LIBCPP_LOCALE__L_EXTENSIONS - int r = wctob_l(*low, __l); -#else - int r = __wctob_l(*low, __l); -#endif + int r = __libcpp_wctob_l(*low, __l); *dest = r != static_cast<int>(WEOF) ? static_cast<char>(r) : dfault; } return low; @@ -1558,22 +1533,14 @@ codecvt<wchar_t, char, mbstate_t>::do_out(state_type& st, { // save state in case it is needed to recover to_nxt on error mbstate_t save_state = st; -#ifdef _LIBCPP_LOCALE__L_EXTENSIONS - size_t n = wcsnrtombs_l(to, &frm_nxt, static_cast<size_t>(fend-frm), - static_cast<size_t>(to_end-to), &st, __l); -#else - size_t n = __wcsnrtombs_l(to, &frm_nxt, fend-frm, to_end-to, &st, __l); -#endif + size_t n = __libcpp_wcsnrtombs_l(to, &frm_nxt, static_cast<size_t>(fend-frm), + static_cast<size_t>(to_end-to), &st, __l); if (n == size_t(-1)) { // need to recover to_nxt for (to_nxt = to; frm != frm_nxt; ++frm) { -#ifdef _LIBCPP_LOCALE__L_EXTENSIONS - n = wcrtomb_l(to_nxt, *frm, &save_state, __l); -#else - n = __wcrtomb_l(to_nxt, *frm, &save_state, __l); -#endif + n = __libcpp_wcrtomb_l(to_nxt, *frm, &save_state, __l); if (n == size_t(-1)) break; to_nxt += n; @@ -1590,11 +1557,7 @@ codecvt<wchar_t, char, mbstate_t>::do_out(state_type& st, { // Try to write the terminating null extern_type tmp[MB_LEN_MAX]; -#ifdef _LIBCPP_LOCALE__L_EXTENSIONS - n = wcrtomb_l(tmp, intern_type(), &st, __l); -#else - n = __wcrtomb_l(tmp, intern_type(), &st, __l); -#endif + n = __libcpp_wcrtomb_l(tmp, intern_type(), &st, __l); if (n == size_t(-1)) // on error return error; if (n > static_cast<size_t>(to_end-to_nxt)) // is there room? @@ -1627,23 +1590,15 @@ codecvt<wchar_t, char, mbstate_t>::do_in(state_type& st, { // save state in case it is needed to recover to_nxt on error mbstate_t save_state = st; -#ifdef _LIBCPP_LOCALE__L_EXTENSIONS - size_t n = mbsnrtowcs_l(to, &frm_nxt, static_cast<size_t>(fend-frm), - static_cast<size_t>(to_end-to), &st, __l); -#else - size_t n = __mbsnrtowcs_l(to, &frm_nxt, fend-frm, to_end-to, &st, __l); -#endif + size_t n = __libcpp_mbsnrtowcs_l(to, &frm_nxt, static_cast<size_t>(fend-frm), + static_cast<size_t>(to_end-to), &st, __l); if (n == size_t(-1)) { // need to recover to_nxt for (to_nxt = to; frm != frm_nxt; ++to_nxt) { -#ifdef _LIBCPP_LOCALE__L_EXTENSIONS - n = mbrtowc_l(to_nxt, frm, static_cast<size_t>(fend-frm), - &save_state, __l); -#else - n = __mbrtowc_l(to_nxt, frm, fend-frm, &save_state, __l); -#endif + n = __libcpp_mbrtowc_l(to_nxt, frm, static_cast<size_t>(fend-frm), + &save_state, __l); switch (n) { case 0: @@ -1671,11 +1626,7 @@ codecvt<wchar_t, char, mbstate_t>::do_in(state_type& st, if (fend != frm_end) // set up next null terminated sequence { // Try to write the terminating null -#ifdef _LIBCPP_LOCALE__L_EXTENSIONS - n = mbrtowc_l(to_nxt, frm_nxt, 1, &st, __l); -#else - n = __mbrtowc_l(to_nxt, frm_nxt, 1, &st, __l); -#endif + n = __libcpp_mbrtowc_l(to_nxt, frm_nxt, 1, &st, __l); if (n != 0) // on error return error; ++to_nxt; @@ -1695,11 +1646,7 @@ codecvt<wchar_t, char, mbstate_t>::do_unshift(state_type& st, { to_nxt = to; extern_type tmp[MB_LEN_MAX]; -#ifdef _LIBCPP_LOCALE__L_EXTENSIONS - size_t n = wcrtomb_l(tmp, intern_type(), &st, __l); -#else - size_t n = __wcrtomb_l(tmp, intern_type(), &st, __l); -#endif + size_t n = __libcpp_wcrtomb_l(tmp, intern_type(), &st, __l); if (n == size_t(-1) || n == 0) // on error return error; --n; @@ -1713,21 +1660,11 @@ codecvt<wchar_t, char, mbstate_t>::do_unshift(state_type& st, int codecvt<wchar_t, char, mbstate_t>::do_encoding() const _NOEXCEPT { -#ifndef __CloudABI__ -#ifdef _LIBCPP_LOCALE__L_EXTENSIONS - if (mbtowc_l(nullptr, nullptr, MB_LEN_MAX, __l) != 0) -#else - if (__mbtowc_l(nullptr, nullptr, MB_LEN_MAX, __l) != 0) -#endif + if (__libcpp_mbtowc_l(nullptr, nullptr, MB_LEN_MAX, __l) != 0) return -1; -#endif // stateless encoding -#ifdef _LIBCPP_LOCALE__L_EXTENSIONS - if (__l == 0 || MB_CUR_MAX_L(__l) == 1) // there are no known constant length encodings -#else - if (__l == 0 || __mb_cur_max_l(__l) == 1) // there are no known constant length encodings -#endif + if (__l == 0 || __libcpp_mb_cur_max_l(__l) == 1) // there are no known constant length encodings return 1; // which take more than 1 char to form a wchar_t return 0; } @@ -1745,11 +1682,7 @@ codecvt<wchar_t, char, mbstate_t>::do_length(state_type& st, int nbytes = 0; for (size_t nwchar_t = 0; nwchar_t < mx && frm != frm_end; ++nwchar_t) { -#ifdef _LIBCPP_LOCALE__L_EXTENSIONS - size_t n = mbrlen_l(frm, static_cast<size_t>(frm_end-frm), &st, __l); -#else - size_t n = __mbrlen_l(frm, frm_end-frm, &st, __l); -#endif + size_t n = __libcpp_mbrlen_l(frm, static_cast<size_t>(frm_end-frm), &st, __l); switch (n) { case 0: @@ -1771,11 +1704,7 @@ codecvt<wchar_t, char, mbstate_t>::do_length(state_type& st, int codecvt<wchar_t, char, mbstate_t>::do_max_length() const _NOEXCEPT { -#ifdef _LIBCPP_LOCALE__L_EXTENSIONS - return __l == 0 ? 1 : static_cast<int>( MB_CUR_MAX_L(__l)); -#else - return __l == 0 ? 1 : static_cast<int>(__mb_cur_max_l(__l)); -#endif + return __l == 0 ? 1 : static_cast<int>(__libcpp_mb_cur_max_l(__l)); } // Valid UTF ranges @@ -2894,10 +2823,10 @@ ucs4_to_utf16le(const uint32_t* frm, const uint32_t* frm_end, const uint32_t*& f to_nxt = to; if (mode & generate_header) { - if (to_end-to_nxt < 2) + if (to_end - to_nxt < 2) return codecvt_base::partial; - *to_nxt++ = static_cast<uint8_t>(0xFF); - *to_nxt++ = static_cast<uint8_t>(0xFE); + *to_nxt++ = static_cast<uint8_t>(0xFF); + *to_nxt++ = static_cast<uint8_t>(0xFE); } for (; frm_nxt < frm_end; ++frm_nxt) { @@ -4333,11 +4262,7 @@ numpunct_byname<char>::__init(const char* nm) throw runtime_error("numpunct_byname<char>::numpunct_byname" " failed to construct for " + string(nm)); #endif // _LIBCPP_NO_EXCEPTIONS -#ifdef _LIBCPP_LOCALE__L_EXTENSIONS - lconv* lc = localeconv_l(loc.get()); -#else - lconv* lc = __localeconv_l(loc.get()); -#endif + lconv* lc = __libcpp_localeconv_l(loc.get()); if (*lc->decimal_point) __decimal_point_ = *lc->decimal_point; if (*lc->thousands_sep) @@ -4376,11 +4301,7 @@ numpunct_byname<wchar_t>::__init(const char* nm) throw runtime_error("numpunct_byname<char>::numpunct_byname" " failed to construct for " + string(nm)); #endif // _LIBCPP_NO_EXCEPTIONS -#ifdef _LIBCPP_LOCALE__L_EXTENSIONS - lconv* lc = localeconv_l(loc.get()); -#else - lconv* lc = __localeconv_l(loc.get()); -#endif + lconv* lc = __libcpp_localeconv_l(loc.get()); if (*lc->decimal_point) __decimal_point_ = *lc->decimal_point; if (*lc->thousands_sep) @@ -4981,11 +4902,7 @@ __time_get_storage<wchar_t>::__analyze(char fmt, const ctype<wchar_t>& ct) wchar_t* wbb = wbuf; mbstate_t mb = {0}; const char* bb = buf; -#ifdef _LIBCPP_LOCALE__L_EXTENSIONS - size_t j = mbsrtowcs_l( wbb, &bb, countof(wbuf), &mb, __loc_); -#else - size_t j = __mbsrtowcs_l( wbb, &bb, countof(wbuf), &mb, __loc_); -#endif + size_t j = __libcpp_mbsrtowcs_l( wbb, &bb, countof(wbuf), &mb, __loc_); if (j == size_t(-1)) __throw_runtime_error("locale not supported"); wchar_t* wbe = wbb + j; @@ -5165,11 +5082,7 @@ __time_get_storage<wchar_t>::init(const ctype<wchar_t>& ct) strftime_l(buf, countof(buf), "%A", &t, __loc_); mb = mbstate_t(); const char* bb = buf; -#ifdef _LIBCPP_LOCALE__L_EXTENSIONS - size_t j = mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_); -#else - size_t j = __mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_); -#endif + size_t j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_); if (j == size_t(-1)) __throw_runtime_error("locale not supported"); wbe = wbuf + j; @@ -5177,11 +5090,7 @@ __time_get_storage<wchar_t>::init(const ctype<wchar_t>& ct) strftime_l(buf, countof(buf), "%a", &t, __loc_); mb = mbstate_t(); bb = buf; -#ifdef _LIBCPP_LOCALE__L_EXTENSIONS - j = mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_); -#else - j = __mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_); -#endif + j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_); if (j == size_t(-1)) __throw_runtime_error("locale not supported"); wbe = wbuf + j; @@ -5194,11 +5103,7 @@ __time_get_storage<wchar_t>::init(const ctype<wchar_t>& ct) strftime_l(buf, countof(buf), "%B", &t, __loc_); mb = mbstate_t(); const char* bb = buf; -#ifdef _LIBCPP_LOCALE__L_EXTENSIONS - size_t j = mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_); -#else - size_t j = __mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_); -#endif + size_t j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_); if (j == size_t(-1)) __throw_runtime_error("locale not supported"); wbe = wbuf + j; @@ -5206,11 +5111,7 @@ __time_get_storage<wchar_t>::init(const ctype<wchar_t>& ct) strftime_l(buf, countof(buf), "%b", &t, __loc_); mb = mbstate_t(); bb = buf; -#ifdef _LIBCPP_LOCALE__L_EXTENSIONS - j = mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_); -#else - j = __mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_); -#endif + j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_); if (j == size_t(-1)) __throw_runtime_error("locale not supported"); wbe = wbuf + j; @@ -5221,11 +5122,7 @@ __time_get_storage<wchar_t>::init(const ctype<wchar_t>& ct) strftime_l(buf, countof(buf), "%p", &t, __loc_); mb = mbstate_t(); const char* bb = buf; -#ifdef _LIBCPP_LOCALE__L_EXTENSIONS - size_t j = mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_); -#else - size_t j = __mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_); -#endif + size_t j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_); if (j == size_t(-1)) __throw_runtime_error("locale not supported"); wbe = wbuf + j; @@ -5234,11 +5131,7 @@ __time_get_storage<wchar_t>::init(const ctype<wchar_t>& ct) strftime_l(buf, countof(buf), "%p", &t, __loc_); mb = mbstate_t(); bb = buf; -#ifdef _LIBCPP_LOCALE__L_EXTENSIONS - j = mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_); -#else - j = __mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_); -#endif + j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_); if (j == size_t(-1)) __throw_runtime_error("locale not supported"); wbe = wbuf + j; @@ -5513,11 +5406,7 @@ __time_put::__do_put(wchar_t* __wb, wchar_t*& __we, const tm* __tm, __do_put(__nar, __ne, __tm, __fmt, __mod); mbstate_t mb = {0}; const char* __nb = __nar; -#ifdef _LIBCPP_LOCALE__L_EXTENSIONS - size_t j = mbsrtowcs_l(__wb, &__nb, countof(__wb, __we), &mb, __loc_); -#else - size_t j = __mbsrtowcs_l(__wb, &__nb, countof(__wb, __we), &mb, __loc_); -#endif + size_t j = __libcpp_mbsrtowcs_l(__wb, &__nb, countof(__wb, __we), &mb, __loc_); if (j == size_t(-1)) __throw_runtime_error("locale not supported"); __we = __wb + j; @@ -5908,11 +5797,7 @@ moneypunct_byname<char, false>::init(const char* nm) throw runtime_error("moneypunct_byname" " failed to construct for " + string(nm)); #endif // _LIBCPP_NO_EXCEPTIONS -#ifdef _LIBCPP_LOCALE__L_EXTENSIONS - lconv* lc = localeconv_l(loc.get()); -#else - lconv* lc = __localeconv_l(loc.get()); -#endif + lconv* lc = __libcpp_localeconv_l(loc.get()); if (*lc->mon_decimal_point) __decimal_point_ = *lc->mon_decimal_point; else @@ -5956,11 +5841,7 @@ moneypunct_byname<char, true>::init(const char* nm) throw runtime_error("moneypunct_byname" " failed to construct for " + string(nm)); #endif // _LIBCPP_NO_EXCEPTIONS -#ifdef _LIBCPP_LOCALE__L_EXTENSIONS - lconv* lc = localeconv_l(loc.get()); -#else - lconv* lc = __localeconv_l(loc.get()); -#endif + lconv* lc = __libcpp_localeconv_l(loc.get()); if (*lc->mon_decimal_point) __decimal_point_ = *lc->mon_decimal_point; else @@ -6021,11 +5902,7 @@ moneypunct_byname<wchar_t, false>::init(const char* nm) throw runtime_error("moneypunct_byname" " failed to construct for " + string(nm)); #endif // _LIBCPP_NO_EXCEPTIONS -#ifdef _LIBCPP_LOCALE__L_EXTENSIONS - lconv* lc = localeconv_l(loc.get()); -#else - lconv* lc = __localeconv_l(loc.get()); -#endif + lconv* lc = __libcpp_localeconv_l(loc.get()); if (*lc->mon_decimal_point) __decimal_point_ = static_cast<wchar_t>(*lc->mon_decimal_point); else @@ -6038,11 +5915,7 @@ moneypunct_byname<wchar_t, false>::init(const char* nm) wchar_t wbuf[100]; mbstate_t mb = {0}; const char* bb = lc->currency_symbol; -#ifdef _LIBCPP_LOCALE__L_EXTENSIONS - size_t j = mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get()); -#else - size_t j = __mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get()); -#endif + size_t j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get()); if (j == size_t(-1)) __throw_runtime_error("locale not supported"); wchar_t* wbe = wbuf + j; @@ -6057,11 +5930,7 @@ moneypunct_byname<wchar_t, false>::init(const char* nm) { mb = mbstate_t(); bb = lc->positive_sign; -#ifdef _LIBCPP_LOCALE__L_EXTENSIONS - j = mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get()); -#else - j = __mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get()); -#endif + j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get()); if (j == size_t(-1)) __throw_runtime_error("locale not supported"); wbe = wbuf + j; @@ -6073,11 +5942,7 @@ moneypunct_byname<wchar_t, false>::init(const char* nm) { mb = mbstate_t(); bb = lc->negative_sign; -#ifdef _LIBCPP_LOCALE__L_EXTENSIONS - j = mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get()); -#else - j = __mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get()); -#endif + j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get()); if (j == size_t(-1)) __throw_runtime_error("locale not supported"); wbe = wbuf + j; @@ -6104,11 +5969,7 @@ moneypunct_byname<wchar_t, true>::init(const char* nm) throw runtime_error("moneypunct_byname" " failed to construct for " + string(nm)); #endif // _LIBCPP_NO_EXCEPTIONS -#ifdef _LIBCPP_LOCALE__L_EXTENSIONS - lconv* lc = localeconv_l(loc.get()); -#else - lconv* lc = __localeconv_l(loc.get()); -#endif + lconv* lc = __libcpp_localeconv_l(loc.get()); if (*lc->mon_decimal_point) __decimal_point_ = static_cast<wchar_t>(*lc->mon_decimal_point); else @@ -6121,11 +5982,7 @@ moneypunct_byname<wchar_t, true>::init(const char* nm) wchar_t wbuf[100]; mbstate_t mb = {0}; const char* bb = lc->int_curr_symbol; -#ifdef _LIBCPP_LOCALE__L_EXTENSIONS - size_t j = mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get()); -#else - size_t j = __mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get()); -#endif + size_t j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get()); if (j == size_t(-1)) __throw_runtime_error("locale not supported"); wchar_t* wbe = wbuf + j; @@ -6144,11 +6001,7 @@ moneypunct_byname<wchar_t, true>::init(const char* nm) { mb = mbstate_t(); bb = lc->positive_sign; -#ifdef _LIBCPP_LOCALE__L_EXTENSIONS - j = mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get()); -#else - j = __mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get()); -#endif + j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get()); if (j == size_t(-1)) __throw_runtime_error("locale not supported"); wbe = wbuf + j; @@ -6164,11 +6017,7 @@ moneypunct_byname<wchar_t, true>::init(const char* nm) { mb = mbstate_t(); bb = lc->negative_sign; -#ifdef _LIBCPP_LOCALE__L_EXTENSIONS - j = mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get()); -#else - j = __mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get()); -#endif + j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get()); if (j == size_t(-1)) __throw_runtime_error("locale not supported"); wbe = wbuf + j; |