git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@134155 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Howard Hinnant 2011-06-30 14:21:55 +00:00
parent a2a08b43ee
commit d318d49e5c

View File

@ -14,6 +14,7 @@
#include "algorithm" #include "algorithm"
#include "algorithm" #include "algorithm"
#include "typeinfo" #include "typeinfo"
#include "type_traits"
#include "clocale" #include "clocale"
#include "cstring" #include "cstring"
#include "cwctype" #include "cwctype"
@ -21,6 +22,98 @@
#include <langinfo.h> #include <langinfo.h>
#include <stdlib.h> #include <stdlib.h>
namespace {
typedef std::remove_pointer<locale_t>::type locale_struct;
typedef std::unique_ptr<locale_struct, decltype(&freelocale)> locale_unique_ptr;
typedef std::unique_ptr<locale_struct, decltype(&uselocale)> locale_raii;
}
namespace with_locale { namespace {
#ifdef __APPLE__
using ::btowc_l;
using ::wctob_l;
using ::wcsnrtombs_l;
using ::wcrtomb_l;
using ::mbsnrtowcs_l;
using ::mbrtowc_l;
using ::mbtowc_l;
using ::mbrlen_l;
using ::localeconv_l;
using ::mbsrtowcs_l;
decltype(MB_CUR_MAX_L(_STD::declval<locale_t>()))
inline _LIBCPP_INLINE_VISIBILITY
mb_cur_max_l(locale_t loc)
{
return MB_CUR_MAX_L(loc);
}
#else
template
<typename Function, typename ...Args>
auto using_locale(Function f, locale_t loc, Args&&... params) -> decltype(f(std::forward<Args>(params)...))
{
locale_raii current(uselocale(loc), uselocale);
return f(std::forward<Args>(params)...);
}
decltype(MB_CUR_MAX)
mb_cur_max_l(locale_t loc)
{
locale_raii current(uselocale(loc), uselocale);
return MB_CUR_MAX;
}
wint_t btowc_l(int c, locale_t l) { return using_locale(&btowc, l, c); }
int wctob_l(wint_t c, locale_t l) { return using_locale(&wctob, l, c); }
size_t wcsnrtombs_l(char * dest,
const wchar_t * * src,
size_t nwc,
size_t len,
mbstate_t * ps,
locale_t l)
{
return using_locale(&wcsnrtombs, l, dest, src, nwc, len, ps);
}
size_t wcrtomb_l(char *s, wchar_t wc, mbstate_t *ps, locale_t l)
{
return using_locale(&wcrtomb, l, s, wc, ps);
}
size_t mbsnrtowcs_l(wchar_t * dest,
const char * * src,
size_t nms,
size_t len,
mbstate_t * ps,
locale_t l)
{
return using_locale(&mbsnrtowcs, l, dest, src, nms, len, ps);
}
size_t mbrtowc_l(wchar_t *pwc, const char *s, size_t n, mbstate_t *ps, locale_t l)
{
return using_locale(&mbrtowc, l, pwc, s, n, ps);
}
int mbtowc_l(wchar_t * pwc, const char * pmb, size_t max, locale_t l)
{
return using_locale(&mbtowc, l, pwc, pmb, max);
}
size_t mbrlen_l(const char *s, size_t n, mbstate_t *ps, locale_t l)
{
return using_locale(&mbrlen, l, s, n, ps);
}
struct lconv *localeconv_l(locale_t l)
{
return using_locale(&localeconv, l);
}
size_t mbsrtowcs_l(wchar_t * dest,
const char * * src,
size_t len,
mbstate_t * ps,
locale_t l)
{
return using_locale(&mbsrtowcs, l, dest, src, len, ps);
}
#endif
} }
_LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_BEGIN_NAMESPACE_STD
namespace { namespace {
@ -1082,49 +1175,33 @@ ctype_byname<wchar_t>::do_tolower(char_type* low, const char_type* high) const
wchar_t wchar_t
ctype_byname<wchar_t>::do_widen(char c) const ctype_byname<wchar_t>::do_widen(char c) const
{ {
#ifdef __APPLE__ return with_locale::btowc_l(c, __l);
return btowc_l(c, __l);
#else
return 0;
#endif
} }
const char* const char*
ctype_byname<wchar_t>::do_widen(const char* low, const char* high, char_type* dest) const ctype_byname<wchar_t>::do_widen(const char* low, const char* high, char_type* dest) const
{ {
#ifdef __APPLE__
for (; low != high; ++low, ++dest) for (; low != high; ++low, ++dest)
*dest = btowc_l(*low, __l); *dest = with_locale::btowc_l(*low, __l);
return low; return low;
#else
return NULL;
#endif
} }
char char
ctype_byname<wchar_t>::do_narrow(char_type c, char dfault) const ctype_byname<wchar_t>::do_narrow(char_type c, char dfault) const
{ {
#ifdef __APPLE__ int r = with_locale::wctob_l(c, __l);
int r = wctob_l(c, __l);
return r != WEOF ? static_cast<char>(r) : dfault; return r != WEOF ? static_cast<char>(r) : dfault;
#else
return 0;
#endif
} }
const wchar_t* const wchar_t*
ctype_byname<wchar_t>::do_narrow(const char_type* low, const char_type* high, char dfault, char* dest) const ctype_byname<wchar_t>::do_narrow(const char_type* low, const char_type* high, char dfault, char* dest) const
{ {
#ifdef __APPLE__
for (; low != high; ++low, ++dest) for (; low != high; ++low, ++dest)
{ {
int r = wctob_l(*low, __l); int r = with_locale::wctob_l(*low, __l);
*dest = r != WEOF ? static_cast<char>(r) : dfault; *dest = r != WEOF ? static_cast<char>(r) : dfault;
} }
return low; return low;
#else
return NULL;
#endif
} }
// template <> class codecvt<char, char, mbstate_t> // template <> class codecvt<char, char, mbstate_t>
@ -1220,7 +1297,6 @@ codecvt<wchar_t, char, mbstate_t>::do_out(state_type& st,
const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt, const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
extern_type* to, extern_type* to_end, extern_type*& to_nxt) const extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
{ {
#ifdef __APPLE__
// look for first internal null in frm // look for first internal null in frm
const intern_type* fend = frm; const intern_type* fend = frm;
for (; fend != frm_end; ++fend) for (; fend != frm_end; ++fend)
@ -1232,13 +1308,13 @@ codecvt<wchar_t, char, mbstate_t>::do_out(state_type& st,
{ {
// save state in case needed to reover to_nxt on error // save state in case needed to reover to_nxt on error
mbstate_t save_state = st; mbstate_t save_state = st;
size_t n = wcsnrtombs_l(to, &frm_nxt, fend-frm, to_end-to, &st, __l); size_t n = with_locale::wcsnrtombs_l(to, &frm_nxt, fend-frm, to_end-to, &st, __l);
if (n == size_t(-1)) if (n == size_t(-1))
{ {
// need to recover to_nxt // need to recover to_nxt
for (to_nxt = to; frm != frm_nxt; ++frm) for (to_nxt = to; frm != frm_nxt; ++frm)
{ {
n = wcrtomb_l(to_nxt, *frm, &save_state, __l); n = with_locale::wcrtomb_l(to_nxt, *frm, &save_state, __l);
if (n == size_t(-1)) if (n == size_t(-1))
break; break;
to_nxt += n; to_nxt += n;
@ -1255,7 +1331,7 @@ codecvt<wchar_t, char, mbstate_t>::do_out(state_type& st,
{ {
// Try to write the terminating null // Try to write the terminating null
extern_type tmp[MB_LEN_MAX]; extern_type tmp[MB_LEN_MAX];
n = wcrtomb_l(tmp, intern_type(), &st, __l); n = with_locale::wcrtomb_l(tmp, intern_type(), &st, __l);
if (n == size_t(-1)) // on error if (n == size_t(-1)) // on error
return error; return error;
if (n > to_end-to_nxt) // is there room? if (n > to_end-to_nxt) // is there room?
@ -1270,9 +1346,6 @@ codecvt<wchar_t, char, mbstate_t>::do_out(state_type& st,
} }
} }
return frm_nxt == frm_end ? ok : partial; return frm_nxt == frm_end ? ok : partial;
#else
return error;
#endif
} }
codecvt<wchar_t, char, mbstate_t>::result codecvt<wchar_t, char, mbstate_t>::result
@ -1280,7 +1353,6 @@ codecvt<wchar_t, char, mbstate_t>::do_in(state_type& st,
const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt, const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
intern_type* to, intern_type* to_end, intern_type*& to_nxt) const intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
{ {
#ifdef __APPLE__
// look for first internal null in frm // look for first internal null in frm
const extern_type* fend = frm; const extern_type* fend = frm;
for (; fend != frm_end; ++fend) for (; fend != frm_end; ++fend)
@ -1292,13 +1364,13 @@ codecvt<wchar_t, char, mbstate_t>::do_in(state_type& st,
{ {
// save state in case needed to reover to_nxt on error // save state in case needed to reover to_nxt on error
mbstate_t save_state = st; mbstate_t save_state = st;
size_t n = mbsnrtowcs_l(to, &frm_nxt, fend-frm, to_end-to, &st, __l); size_t n = with_locale::mbsnrtowcs_l(to, &frm_nxt, fend-frm, to_end-to, &st, __l);
if (n == size_t(-1)) if (n == size_t(-1))
{ {
// need to recover to_nxt // need to recover to_nxt
for (to_nxt = to; frm != frm_nxt; ++to_nxt) for (to_nxt = to; frm != frm_nxt; ++to_nxt)
{ {
n = mbrtowc_l(to_nxt, frm, fend-frm, &save_state, __l); n = with_locale::mbrtowc_l(to_nxt, frm, fend-frm, &save_state, __l);
switch (n) switch (n)
{ {
case 0: case 0:
@ -1326,7 +1398,7 @@ codecvt<wchar_t, char, mbstate_t>::do_in(state_type& st,
if (fend != frm_end) // set up next null terminated sequence if (fend != frm_end) // set up next null terminated sequence
{ {
// Try to write the terminating null // Try to write the terminating null
n = mbrtowc_l(to_nxt, frm_nxt, 1, &st, __l); n = with_locale::mbrtowc_l(to_nxt, frm_nxt, 1, &st, __l);
if (n != 0) // on error if (n != 0) // on error
return error; return error;
++to_nxt; ++to_nxt;
@ -1338,19 +1410,15 @@ codecvt<wchar_t, char, mbstate_t>::do_in(state_type& st,
} }
} }
return frm_nxt == frm_end ? ok : partial; return frm_nxt == frm_end ? ok : partial;
#else
return error;
#endif
} }
codecvt<wchar_t, char, mbstate_t>::result codecvt<wchar_t, char, mbstate_t>::result
codecvt<wchar_t, char, mbstate_t>::do_unshift(state_type& st, codecvt<wchar_t, char, mbstate_t>::do_unshift(state_type& st,
extern_type* to, extern_type* to_end, extern_type*& to_nxt) const extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
{ {
#ifdef __APPLE__
to_nxt = to; to_nxt = to;
extern_type tmp[MB_LEN_MAX]; extern_type tmp[MB_LEN_MAX];
size_t n = wcrtomb_l(tmp, intern_type(), &st, __l); size_t n = with_locale::wcrtomb_l(tmp, intern_type(), &st, __l);
if (n == size_t(-1) || n == 0) // on error if (n == size_t(-1) || n == 0) // on error
return error; return error;
--n; --n;
@ -1359,26 +1427,19 @@ codecvt<wchar_t, char, mbstate_t>::do_unshift(state_type& st,
for (extern_type* p = tmp; n; --n) // write it for (extern_type* p = tmp; n; --n) // write it
*to_nxt++ = *p++; *to_nxt++ = *p++;
return ok; return ok;
#else
return error;
#endif
} }
int int
codecvt<wchar_t, char, mbstate_t>::do_encoding() const _NOEXCEPT codecvt<wchar_t, char, mbstate_t>::do_encoding() const _NOEXCEPT
{ {
#ifdef __APPLE__ if (with_locale::mbtowc_l((wchar_t*) 0, (const char*) 0, MB_LEN_MAX, __l) == 0)
if (mbtowc_l(0, 0, MB_LEN_MAX, __l) == 0)
{ {
// stateless encoding // stateless encoding
if (__l == 0 || MB_CUR_MAX_L(__l) == 1) // there are no known constant length encodings if (__l == 0 || with_locale::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 1; // which take more than 1 char to form a wchar_t
return 0; return 0;
} }
return -1; return -1;
#else
return 0;
#endif
} }
bool bool
@ -1391,11 +1452,10 @@ int
codecvt<wchar_t, char, mbstate_t>::do_length(state_type& st, codecvt<wchar_t, char, mbstate_t>::do_length(state_type& st,
const extern_type* frm, const extern_type* frm_end, size_t mx) const const extern_type* frm, const extern_type* frm_end, size_t mx) const
{ {
#ifdef __APPLE__
int nbytes = 0; int nbytes = 0;
for (size_t nwchar_t = 0; nwchar_t < mx && frm != frm_end; ++nwchar_t) for (size_t nwchar_t = 0; nwchar_t < mx && frm != frm_end; ++nwchar_t)
{ {
size_t n = mbrlen_l(frm, frm_end-frm, &st, __l); size_t n = with_locale::mbrlen_l(frm, frm_end-frm, &st, __l);
switch (n) switch (n)
{ {
case 0: case 0:
@ -1412,19 +1472,12 @@ codecvt<wchar_t, char, mbstate_t>::do_length(state_type& st,
} }
} }
return nbytes; return nbytes;
#else
return 0;
#endif
} }
int int
codecvt<wchar_t, char, mbstate_t>::do_max_length() const _NOEXCEPT codecvt<wchar_t, char, mbstate_t>::do_max_length() const _NOEXCEPT
{ {
#ifdef __APPLE__ return __l == 0 ? 1 : with_locale::mb_cur_max_l(__l);
return __l == 0 ? 1 : MB_CUR_MAX_L(__l);
#else
return 0;
#endif
} }
// Valid UTF ranges // Valid UTF ranges
@ -3965,16 +4018,15 @@ numpunct_byname<char>::~numpunct_byname()
void void
numpunct_byname<char>::__init(const char* nm) numpunct_byname<char>::__init(const char* nm)
{ {
#ifdef __APPLE__
if (strcmp(nm, "C") != 0) if (strcmp(nm, "C") != 0)
{ {
unique_ptr<_xlocale, int(*)(locale_t)> loc(newlocale(LC_ALL_MASK, nm, 0), freelocale); locale_unique_ptr loc(newlocale(LC_ALL_MASK, nm, 0), freelocale);
#ifndef _LIBCPP_NO_EXCEPTIONS #ifndef _LIBCPP_NO_EXCEPTIONS
if (loc == 0) if (loc == 0)
throw runtime_error("numpunct_byname<char>::numpunct_byname" throw runtime_error("numpunct_byname<char>::numpunct_byname"
" failed to construct for " + string(nm)); " failed to construct for " + string(nm));
#endif // _LIBCPP_NO_EXCEPTIONS #endif // _LIBCPP_NO_EXCEPTIONS
lconv* lc = localeconv_l(loc.get()); lconv* lc = with_locale::localeconv_l(loc.get());
if (*lc->decimal_point) if (*lc->decimal_point)
__decimal_point_ = *lc->decimal_point; __decimal_point_ = *lc->decimal_point;
if (*lc->thousands_sep) if (*lc->thousands_sep)
@ -3982,7 +4034,6 @@ numpunct_byname<char>::__init(const char* nm)
__grouping_ = lc->grouping; __grouping_ = lc->grouping;
// locallization for truename and falsename is not available // locallization for truename and falsename is not available
} }
#endif
} }
// numpunct_byname<wchar_t> // numpunct_byname<wchar_t>
@ -4006,16 +4057,15 @@ numpunct_byname<wchar_t>::~numpunct_byname()
void void
numpunct_byname<wchar_t>::__init(const char* nm) numpunct_byname<wchar_t>::__init(const char* nm)
{ {
#ifdef __APPLE__
if (strcmp(nm, "C") != 0) if (strcmp(nm, "C") != 0)
{ {
unique_ptr<_xlocale, int(*)(locale_t)> loc(newlocale(LC_ALL_MASK, nm, 0), freelocale); locale_unique_ptr loc(newlocale(LC_ALL_MASK, nm, 0), freelocale);
#ifndef _LIBCPP_NO_EXCEPTIONS #ifndef _LIBCPP_NO_EXCEPTIONS
if (loc == 0) if (loc == 0)
throw runtime_error("numpunct_byname<char>::numpunct_byname" throw runtime_error("numpunct_byname<char>::numpunct_byname"
" failed to construct for " + string(nm)); " failed to construct for " + string(nm));
#endif // _LIBCPP_NO_EXCEPTIONS #endif // _LIBCPP_NO_EXCEPTIONS
lconv* lc = localeconv_l(loc.get()); lconv* lc = with_locale::localeconv_l(loc.get());
if (*lc->decimal_point) if (*lc->decimal_point)
__decimal_point_ = *lc->decimal_point; __decimal_point_ = *lc->decimal_point;
if (*lc->thousands_sep) if (*lc->thousands_sep)
@ -4023,7 +4073,6 @@ numpunct_byname<wchar_t>::__init(const char* nm)
__grouping_ = lc->grouping; __grouping_ = lc->grouping;
// locallization for truename and falsename is not available // locallization for truename and falsename is not available
} }
#endif
} }
// num_get helpers // num_get helpers
@ -4588,7 +4637,6 @@ template <>
wstring wstring
__time_get_storage<wchar_t>::__analyze(char fmt, const ctype<wchar_t>& ct) __time_get_storage<wchar_t>::__analyze(char fmt, const ctype<wchar_t>& ct)
{ {
#ifdef __APPLE__
tm t; tm t;
t.tm_sec = 59; t.tm_sec = 59;
t.tm_min = 55; t.tm_min = 55;
@ -4608,7 +4656,7 @@ __time_get_storage<wchar_t>::__analyze(char fmt, const ctype<wchar_t>& ct)
wchar_t* wbb = wbuf; wchar_t* wbb = wbuf;
mbstate_t mb = {0}; mbstate_t mb = {0};
const char* bb = buf; const char* bb = buf;
size_t i = mbsrtowcs_l(wbb, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_); size_t i = with_locale::mbsrtowcs_l( wbb, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
if (i == -1) if (i == -1)
__throw_runtime_error("locale not supported"); __throw_runtime_error("locale not supported");
wchar_t* wbe = wbb + i; wchar_t* wbe = wbb + i;
@ -4733,9 +4781,6 @@ __time_get_storage<wchar_t>::__analyze(char fmt, const ctype<wchar_t>& ct)
++wbb; ++wbb;
} }
return result; return result;
#else
return wstring();
#endif
} }
template <> template <>
@ -4779,7 +4824,6 @@ template <>
void void
__time_get_storage<wchar_t>::init(const ctype<wchar_t>& ct) __time_get_storage<wchar_t>::init(const ctype<wchar_t>& ct)
{ {
#ifdef __APPLE__
tm t = {0}; tm t = {0};
char buf[100]; char buf[100];
size_t be; size_t be;
@ -4793,7 +4837,7 @@ __time_get_storage<wchar_t>::init(const ctype<wchar_t>& ct)
be = strftime_l(buf, 100, "%A", &t, __loc_); be = strftime_l(buf, 100, "%A", &t, __loc_);
mb = mbstate_t(); mb = mbstate_t();
const char* bb = buf; const char* bb = buf;
size_t j = mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_); size_t j = with_locale::mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
if (j == -1) if (j == -1)
__throw_runtime_error("locale not supported"); __throw_runtime_error("locale not supported");
wbe = wbuf + j; wbe = wbuf + j;
@ -4801,7 +4845,7 @@ __time_get_storage<wchar_t>::init(const ctype<wchar_t>& ct)
be = strftime_l(buf, 100, "%a", &t, __loc_); be = strftime_l(buf, 100, "%a", &t, __loc_);
mb = mbstate_t(); mb = mbstate_t();
bb = buf; bb = buf;
j = mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_); j = with_locale::mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
if (j == -1) if (j == -1)
__throw_runtime_error("locale not supported"); __throw_runtime_error("locale not supported");
wbe = wbuf + j; wbe = wbuf + j;
@ -4814,7 +4858,7 @@ __time_get_storage<wchar_t>::init(const ctype<wchar_t>& ct)
be = strftime_l(buf, 100, "%B", &t, __loc_); be = strftime_l(buf, 100, "%B", &t, __loc_);
mb = mbstate_t(); mb = mbstate_t();
const char* bb = buf; const char* bb = buf;
size_t j = mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_); size_t j = with_locale::mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
if (j == -1) if (j == -1)
__throw_runtime_error("locale not supported"); __throw_runtime_error("locale not supported");
wbe = wbuf + j; wbe = wbuf + j;
@ -4822,7 +4866,7 @@ __time_get_storage<wchar_t>::init(const ctype<wchar_t>& ct)
be = strftime_l(buf, 100, "%b", &t, __loc_); be = strftime_l(buf, 100, "%b", &t, __loc_);
mb = mbstate_t(); mb = mbstate_t();
bb = buf; bb = buf;
j = mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_); j = with_locale::mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
if (j == -1) if (j == -1)
__throw_runtime_error("locale not supported"); __throw_runtime_error("locale not supported");
wbe = wbuf + j; wbe = wbuf + j;
@ -4833,7 +4877,7 @@ __time_get_storage<wchar_t>::init(const ctype<wchar_t>& ct)
be = strftime_l(buf, 100, "%p", &t, __loc_); be = strftime_l(buf, 100, "%p", &t, __loc_);
mb = mbstate_t(); mb = mbstate_t();
const char* bb = buf; const char* bb = buf;
size_t j = mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_); size_t j = with_locale::mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
if (j == -1) if (j == -1)
__throw_runtime_error("locale not supported"); __throw_runtime_error("locale not supported");
wbe = wbuf + j; wbe = wbuf + j;
@ -4842,7 +4886,7 @@ __time_get_storage<wchar_t>::init(const ctype<wchar_t>& ct)
be = strftime_l(buf, 100, "%p", &t, __loc_); be = strftime_l(buf, 100, "%p", &t, __loc_);
mb = mbstate_t(); mb = mbstate_t();
bb = buf; bb = buf;
j = mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_); j = with_locale::mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
if (j == -1) if (j == -1)
__throw_runtime_error("locale not supported"); __throw_runtime_error("locale not supported");
wbe = wbuf + j; wbe = wbuf + j;
@ -4851,7 +4895,6 @@ __time_get_storage<wchar_t>::init(const ctype<wchar_t>& ct)
__r_ = __analyze('r', ct); __r_ = __analyze('r', ct);
__x_ = __analyze('x', ct); __x_ = __analyze('x', ct);
__X_ = __analyze('X', ct); __X_ = __analyze('X', ct);
#endif
} }
template <class CharT> template <class CharT>
@ -5113,17 +5156,15 @@ void
__time_put::__do_put(wchar_t* __wb, wchar_t*& __we, const tm* __tm, __time_put::__do_put(wchar_t* __wb, wchar_t*& __we, const tm* __tm,
char __fmt, char __mod) const char __fmt, char __mod) const
{ {
#ifdef __APPLE__
char __nar[100]; char __nar[100];
char* __ne = __nar + 100; char* __ne = __nar + 100;
__do_put(__nar, __ne, __tm, __fmt, __mod); __do_put(__nar, __ne, __tm, __fmt, __mod);
mbstate_t mb = {0}; mbstate_t mb = {0};
const char* __nb = __nar; const char* __nb = __nar;
size_t j = mbsrtowcs_l(__wb, &__nb, 100, &mb, __loc_); size_t j = with_locale::mbsrtowcs_l(__wb, &__nb, 100, &mb, __loc_);
if (j == -1) if (j == -1)
__throw_runtime_error("locale not supported"); __throw_runtime_error("locale not supported");
__we = __wb + j; __we = __wb + j;
#endif
} }
// moneypunct_byname // moneypunct_byname
@ -5368,15 +5409,14 @@ template<>
void void
moneypunct_byname<char, false>::init(const char* nm) moneypunct_byname<char, false>::init(const char* nm)
{ {
#ifdef __APPLE__
typedef moneypunct<char, false> base; typedef moneypunct<char, false> base;
unique_ptr<_xlocale, int(*)(locale_t)> loc(newlocale(LC_ALL_MASK, nm, 0), freelocale); locale_unique_ptr loc(newlocale(LC_ALL_MASK, nm, 0), freelocale);
#ifndef _LIBCPP_NO_EXCEPTIONS #ifndef _LIBCPP_NO_EXCEPTIONS
if (loc == 0) if (loc == 0)
throw runtime_error("moneypunct_byname" throw runtime_error("moneypunct_byname"
" failed to construct for " + string(nm)); " failed to construct for " + string(nm));
#endif // _LIBCPP_NO_EXCEPTIONS #endif // _LIBCPP_NO_EXCEPTIONS
lconv* lc = localeconv_l(loc.get()); lconv* lc = with_locale::localeconv_l(loc.get());
if (*lc->mon_decimal_point) if (*lc->mon_decimal_point)
__decimal_point_ = *lc->mon_decimal_point; __decimal_point_ = *lc->mon_decimal_point;
else else
@ -5401,22 +5441,20 @@ moneypunct_byname<char, false>::init(const char* nm)
__negative_sign_ = lc->negative_sign; __negative_sign_ = lc->negative_sign;
__init_pat(__pos_format_, lc->p_cs_precedes, lc->p_sep_by_space, lc->p_sign_posn); __init_pat(__pos_format_, lc->p_cs_precedes, lc->p_sep_by_space, lc->p_sign_posn);
__init_pat(__neg_format_, lc->n_cs_precedes, lc->n_sep_by_space, lc->n_sign_posn); __init_pat(__neg_format_, lc->n_cs_precedes, lc->n_sep_by_space, lc->n_sign_posn);
#endif
} }
template<> template<>
void void
moneypunct_byname<char, true>::init(const char* nm) moneypunct_byname<char, true>::init(const char* nm)
{ {
#ifdef __APPLE__
typedef moneypunct<char, true> base; typedef moneypunct<char, true> base;
unique_ptr<_xlocale, int(*)(locale_t)> loc(newlocale(LC_ALL_MASK, nm, 0), freelocale); locale_unique_ptr loc(newlocale(LC_ALL_MASK, nm, 0), freelocale);
#ifndef _LIBCPP_NO_EXCEPTIONS #ifndef _LIBCPP_NO_EXCEPTIONS
if (loc == 0) if (loc == 0)
throw runtime_error("moneypunct_byname" throw runtime_error("moneypunct_byname"
" failed to construct for " + string(nm)); " failed to construct for " + string(nm));
#endif // _LIBCPP_NO_EXCEPTIONS #endif // _LIBCPP_NO_EXCEPTIONS
lconv* lc = localeconv_l(loc.get()); lconv* lc = with_locale::localeconv_l(loc.get());
if (*lc->mon_decimal_point) if (*lc->mon_decimal_point)
__decimal_point_ = *lc->mon_decimal_point; __decimal_point_ = *lc->mon_decimal_point;
else else
@ -5441,22 +5479,20 @@ moneypunct_byname<char, true>::init(const char* nm)
__negative_sign_ = lc->negative_sign; __negative_sign_ = lc->negative_sign;
__init_pat(__pos_format_, lc->int_p_cs_precedes, lc->int_p_sep_by_space, lc->int_p_sign_posn); __init_pat(__pos_format_, lc->int_p_cs_precedes, lc->int_p_sep_by_space, lc->int_p_sign_posn);
__init_pat(__neg_format_, lc->int_n_cs_precedes, lc->int_n_sep_by_space, lc->int_n_sign_posn); __init_pat(__neg_format_, lc->int_n_cs_precedes, lc->int_n_sep_by_space, lc->int_n_sign_posn);
#endif
} }
template<> template<>
void void
moneypunct_byname<wchar_t, false>::init(const char* nm) moneypunct_byname<wchar_t, false>::init(const char* nm)
{ {
#ifdef __APPLE__
typedef moneypunct<wchar_t, false> base; typedef moneypunct<wchar_t, false> base;
unique_ptr<_xlocale, int(*)(locale_t)> loc(newlocale(LC_ALL_MASK, nm, 0), freelocale); locale_unique_ptr loc(newlocale(LC_ALL_MASK, nm, 0), freelocale);
#ifndef _LIBCPP_NO_EXCEPTIONS #ifndef _LIBCPP_NO_EXCEPTIONS
if (loc == 0) if (loc == 0)
throw runtime_error("moneypunct_byname" throw runtime_error("moneypunct_byname"
" failed to construct for " + string(nm)); " failed to construct for " + string(nm));
#endif // _LIBCPP_NO_EXCEPTIONS #endif // _LIBCPP_NO_EXCEPTIONS
lconv* lc = localeconv_l(loc.get()); lconv* lc = with_locale::localeconv_l(loc.get());
if (*lc->mon_decimal_point) if (*lc->mon_decimal_point)
__decimal_point_ = static_cast<wchar_t>(*lc->mon_decimal_point); __decimal_point_ = static_cast<wchar_t>(*lc->mon_decimal_point);
else else
@ -5469,7 +5505,7 @@ moneypunct_byname<wchar_t, false>::init(const char* nm)
wchar_t wbuf[100]; wchar_t wbuf[100];
mbstate_t mb = {0}; mbstate_t mb = {0};
const char* bb = lc->currency_symbol; const char* bb = lc->currency_symbol;
size_t j = mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get()); size_t j = with_locale::mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
if (j == -1) if (j == -1)
__throw_runtime_error("locale not supported"); __throw_runtime_error("locale not supported");
wchar_t* wbe = wbuf + j; wchar_t* wbe = wbuf + j;
@ -5484,7 +5520,7 @@ moneypunct_byname<wchar_t, false>::init(const char* nm)
{ {
mb = mbstate_t(); mb = mbstate_t();
bb = lc->positive_sign; bb = lc->positive_sign;
j = mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get()); j = with_locale::mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
if (j == -1) if (j == -1)
__throw_runtime_error("locale not supported"); __throw_runtime_error("locale not supported");
wbe = wbuf + j; wbe = wbuf + j;
@ -5496,7 +5532,7 @@ moneypunct_byname<wchar_t, false>::init(const char* nm)
{ {
mb = mbstate_t(); mb = mbstate_t();
bb = lc->negative_sign; bb = lc->negative_sign;
j = mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get()); j = with_locale::mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
if (j == -1) if (j == -1)
__throw_runtime_error("locale not supported"); __throw_runtime_error("locale not supported");
wbe = wbuf + j; wbe = wbuf + j;
@ -5504,22 +5540,20 @@ moneypunct_byname<wchar_t, false>::init(const char* nm)
} }
__init_pat(__pos_format_, lc->p_cs_precedes, lc->p_sep_by_space, lc->p_sign_posn); __init_pat(__pos_format_, lc->p_cs_precedes, lc->p_sep_by_space, lc->p_sign_posn);
__init_pat(__neg_format_, lc->n_cs_precedes, lc->n_sep_by_space, lc->n_sign_posn); __init_pat(__neg_format_, lc->n_cs_precedes, lc->n_sep_by_space, lc->n_sign_posn);
#endif
} }
template<> template<>
void void
moneypunct_byname<wchar_t, true>::init(const char* nm) moneypunct_byname<wchar_t, true>::init(const char* nm)
{ {
#ifdef __APPLE__
typedef moneypunct<wchar_t, true> base; typedef moneypunct<wchar_t, true> base;
unique_ptr<_xlocale, int(*)(locale_t)> loc(newlocale(LC_ALL_MASK, nm, 0), freelocale); locale_unique_ptr loc(newlocale(LC_ALL_MASK, nm, 0), freelocale);
#ifndef _LIBCPP_NO_EXCEPTIONS #ifndef _LIBCPP_NO_EXCEPTIONS
if (loc == 0) if (loc == 0)
throw runtime_error("moneypunct_byname" throw runtime_error("moneypunct_byname"
" failed to construct for " + string(nm)); " failed to construct for " + string(nm));
#endif // _LIBCPP_NO_EXCEPTIONS #endif // _LIBCPP_NO_EXCEPTIONS
lconv* lc = localeconv_l(loc.get()); lconv* lc = with_locale::localeconv_l(loc.get());
if (*lc->mon_decimal_point) if (*lc->mon_decimal_point)
__decimal_point_ = static_cast<wchar_t>(*lc->mon_decimal_point); __decimal_point_ = static_cast<wchar_t>(*lc->mon_decimal_point);
else else
@ -5532,7 +5566,7 @@ moneypunct_byname<wchar_t, true>::init(const char* nm)
wchar_t wbuf[100]; wchar_t wbuf[100];
mbstate_t mb = {0}; mbstate_t mb = {0};
const char* bb = lc->int_curr_symbol; const char* bb = lc->int_curr_symbol;
size_t j = mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get()); size_t j = with_locale::mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
if (j == -1) if (j == -1)
__throw_runtime_error("locale not supported"); __throw_runtime_error("locale not supported");
wchar_t* wbe = wbuf + j; wchar_t* wbe = wbuf + j;
@ -5547,7 +5581,7 @@ moneypunct_byname<wchar_t, true>::init(const char* nm)
{ {
mb = mbstate_t(); mb = mbstate_t();
bb = lc->positive_sign; bb = lc->positive_sign;
j = mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get()); j = with_locale::mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
if (j == -1) if (j == -1)
__throw_runtime_error("locale not supported"); __throw_runtime_error("locale not supported");
wbe = wbuf + j; wbe = wbuf + j;
@ -5559,7 +5593,7 @@ moneypunct_byname<wchar_t, true>::init(const char* nm)
{ {
mb = mbstate_t(); mb = mbstate_t();
bb = lc->negative_sign; bb = lc->negative_sign;
j = mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get()); j = with_locale::mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
if (j == -1) if (j == -1)
__throw_runtime_error("locale not supported"); __throw_runtime_error("locale not supported");
wbe = wbuf + j; wbe = wbuf + j;
@ -5567,7 +5601,6 @@ moneypunct_byname<wchar_t, true>::init(const char* nm)
} }
__init_pat(__pos_format_, lc->int_p_cs_precedes, lc->int_p_sep_by_space, lc->int_p_sign_posn); __init_pat(__pos_format_, lc->int_p_cs_precedes, lc->int_p_sep_by_space, lc->int_p_sign_posn);
__init_pat(__neg_format_, lc->int_n_cs_precedes, lc->int_n_sep_by_space, lc->int_n_sign_posn); __init_pat(__neg_format_, lc->int_n_cs_precedes, lc->int_n_sep_by_space, lc->int_n_sign_posn);
#endif
} }
void __do_nothing(void*) {} void __do_nothing(void*) {}