aboutsummaryrefslogtreecommitdiff
path: root/src/locale.cpp
diff options
context:
space:
mode:
authorDavid Chisnall <theraven@FreeBSD.org>2013-02-07 13:09:19 +0000
committerDavid Chisnall <theraven@FreeBSD.org>2013-02-07 13:09:19 +0000
commitc7f918d0681828afdbddfdcc354b6f3dfc2a7b68 (patch)
treed1f057460d329356b56f67bf5740b7393c925844 /src/locale.cpp
parentfbd326037ffe8b31f74ce56deb05b6432b26665c (diff)
downloadsrc-c7f918d0681828afdbddfdcc354b6f3dfc2a7b68.tar.gz
src-c7f918d0681828afdbddfdcc354b6f3dfc2a7b68.zip
Import new libc++ to vendor branch.vendor/libc++/r174563
Notes
Notes: svn path=/vendor/libc++/dist/; revision=246468 svn path=/vendor/libc++/r174563/; revision=246469; tag=vendor/libc++/r174563
Diffstat (limited to 'src/locale.cpp')
-rw-r--r--src/locale.cpp150
1 files changed, 97 insertions, 53 deletions
diff --git a/src/locale.cpp b/src/locale.cpp
index 542c0d7a20ff..53a8a4cc1f08 100644
--- a/src/locale.cpp
+++ b/src/locale.cpp
@@ -81,8 +81,35 @@ make(A0 a0, A1 a1, A2 a2)
return *(T*)&buf;
}
+template <typename T, size_t N>
+inline
+_LIBCPP_CONSTEXPR
+size_t
+countof(const T (&)[N])
+{
+ return N;
+}
+
+template <typename T>
+inline
+_LIBCPP_CONSTEXPR
+size_t
+countof(const T * const begin, const T * const end)
+{
+ return static_cast<size_t>(end - begin);
+}
+
}
+const locale::category locale::none;
+const locale::category locale::collate;
+const locale::category locale::ctype;
+const locale::category locale::monetary;
+const locale::category locale::numeric;
+const locale::category locale::time;
+const locale::category locale::messages;
+const locale::category locale::all;
+
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wpadded"
@@ -197,6 +224,11 @@ locale::__imp::__imp(const string& name, size_t refs)
#endif // _LIBCPP_NO_EXCEPTIONS
}
+// NOTE avoid the `base class should be explicitly initialized in the
+// copy constructor` warning emitted by GCC
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wextra"
+
locale::__imp::__imp(const __imp& other)
: facets_(max<size_t>(N, other.facets_.size())),
name_(other.name_)
@@ -207,6 +239,8 @@ locale::__imp::__imp(const __imp& other)
facets_[i]->__add_shared();
}
+#pragma GCC diagnostic pop
+
locale::__imp::__imp(const __imp& other, const string& name, locale::category c)
: facets_(N),
name_("*")
@@ -691,6 +725,19 @@ collate_byname<wchar_t>::do_transform(const char_type* lo, const char_type* hi)
// template <> class ctype<wchar_t>;
+const ctype_base::mask ctype_base::space;
+const ctype_base::mask ctype_base::print;
+const ctype_base::mask ctype_base::cntrl;
+const ctype_base::mask ctype_base::upper;
+const ctype_base::mask ctype_base::lower;
+const ctype_base::mask ctype_base::alpha;
+const ctype_base::mask ctype_base::digit;
+const ctype_base::mask ctype_base::punct;
+const ctype_base::mask ctype_base::xdigit;
+const ctype_base::mask ctype_base::blank;
+const ctype_base::mask ctype_base::alnum;
+const ctype_base::mask ctype_base::graph;
+
locale::id ctype<wchar_t>::id;
ctype<wchar_t>::~ctype()
@@ -843,7 +890,7 @@ ctype<char>::do_toupper(char_type c) const
return isascii(c) ?
static_cast<char>(_DefaultRuneLocale.__mapupper[static_cast<ptrdiff_t>(c)]) : c;
#elif defined(__GLIBC__)
- return isascii(c) ? __classic_upper_table()[c] : c;
+ return isascii(c) ? __classic_upper_table()[static_cast<size_t>(c)] : c;
#else
return (isascii(c) && islower_l(c, __cloc())) ? c-'a'+'A' : c;
#endif
@@ -857,7 +904,7 @@ ctype<char>::do_toupper(char_type* low, const char_type* high) const
*low = isascii(*low) ?
static_cast<char>(_DefaultRuneLocale.__mapupper[static_cast<ptrdiff_t>(*low)]) : *low;
#elif defined(__GLIBC__)
- *low = isascii(*low) ? __classic_upper_table()[*low] : *low;
+ *low = isascii(*low) ? __classic_upper_table()[static_cast<size_t>(*low)] : *low;
#else
*low = (isascii(*low) && islower_l(*low, __cloc())) ? *low-'a'+'A' : *low;
#endif
@@ -871,7 +918,7 @@ ctype<char>::do_tolower(char_type c) const
return isascii(c) ?
static_cast<char>(_DefaultRuneLocale.__maplower[static_cast<ptrdiff_t>(c)]) : c;
#elif defined(__GLIBC__)
- return isascii(c) ? __classic_lower_table()[c] : c;
+ return isascii(c) ? __classic_lower_table()[static_cast<size_t>(c)] : c;
#else
return (isascii(c) && isupper_l(c, __cloc())) ? c-'A'+'a' : c;
#endif
@@ -884,7 +931,7 @@ ctype<char>::do_tolower(char_type* low, const char_type* high) const
#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
*low = isascii(*low) ? static_cast<char>(_DefaultRuneLocale.__maplower[static_cast<ptrdiff_t>(*low)]) : *low;
#elif defined(__GLIBC__)
- *low = isascii(*low) ? __classic_lower_table()[*low] : *low;
+ *low = isascii(*low) ? __classic_lower_table()[static_cast<size_t>(*low)] : *low;
#else
*low = (isascii(*low) && isupper_l(*low, __cloc())) ? *low-'A'+'a' : *low;
#endif
@@ -1207,7 +1254,7 @@ ctype_byname<wchar_t>::do_narrow(char_type c, char dfault) const
#else
int r = __wctob_l(c, __l);
#endif
- return r != WEOF ? static_cast<char>(r) : dfault;
+ return r != static_cast<int>(WEOF) ? static_cast<char>(r) : dfault;
}
const wchar_t*
@@ -1220,7 +1267,7 @@ ctype_byname<wchar_t>::do_narrow(const char_type* low, const char_type* high, ch
#else
int r = __wctob_l(*low, __l);
#endif
- *dest = r != WEOF ? static_cast<char>(r) : dfault;
+ *dest = r != static_cast<int>(WEOF) ? static_cast<char>(r) : dfault;
}
return low;
}
@@ -2619,7 +2666,6 @@ utf16be_to_ucs4_length(const uint8_t* frm, const uint8_t* frm_end,
codecvt_mode mode = codecvt_mode(0))
{
const uint8_t* frm_nxt = frm;
- frm_nxt = frm;
if (mode & consume_header)
{
if (frm_end-frm_nxt >= 2 && frm_nxt[0] == 0xFE && frm_nxt[1] == 0xFF)
@@ -2752,7 +2798,6 @@ utf16le_to_ucs4_length(const uint8_t* frm, const uint8_t* frm_end,
codecvt_mode mode = codecvt_mode(0))
{
const uint8_t* frm_nxt = frm;
- frm_nxt = frm;
if (mode & consume_header)
{
if (frm_end-frm_nxt >= 2 && frm_nxt[0] == 0xFF && frm_nxt[1] == 0xFE)
@@ -2847,7 +2892,6 @@ utf16be_to_ucs2_length(const uint8_t* frm, const uint8_t* frm_end,
codecvt_mode mode = codecvt_mode(0))
{
const uint8_t* frm_nxt = frm;
- frm_nxt = frm;
if (mode & consume_header)
{
if (frm_end-frm_nxt >= 2 && frm_nxt[0] == 0xFE && frm_nxt[1] == 0xFF)
@@ -4559,6 +4603,7 @@ __time_get::~__time_get()
}
#pragma clang diagnostic ignored "-Wmissing-field-initializers"
+#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
template <>
string
@@ -4578,7 +4623,7 @@ __time_get_storage<char>::__analyze(char fmt, const ctype<char>& ct)
char f[3] = {0};
f[0] = '%';
f[1] = fmt;
- size_t n = strftime_l(buf, 100, f, &t, __loc_);
+ size_t n = strftime_l(buf, countof(buf), f, &t, __loc_);
char* bb = buf;
char* be = buf + n;
string result;
@@ -4724,15 +4769,15 @@ __time_get_storage<wchar_t>::__analyze(char fmt, const ctype<wchar_t>& ct)
char f[3] = {0};
f[0] = '%';
f[1] = fmt;
- strftime_l(buf, 100, f, &t, __loc_);
+ strftime_l(buf, countof(buf), f, &t, __loc_);
wchar_t wbuf[100];
wchar_t* wbb = wbuf;
mbstate_t mb = {0};
const char* bb = buf;
#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
- size_t j = mbsrtowcs_l( wbb, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
+ size_t j = mbsrtowcs_l( wbb, &bb, countof(wbuf), &mb, __loc_);
#else
- size_t j = __mbsrtowcs_l( wbb, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
+ size_t j = __mbsrtowcs_l( wbb, &bb, countof(wbuf), &mb, __loc_);
#endif
if (j == size_t(-1))
__throw_runtime_error("locale not supported");
@@ -4870,26 +4915,26 @@ __time_get_storage<char>::init(const ctype<char>& ct)
for (int i = 0; i < 7; ++i)
{
t.tm_wday = i;
- strftime_l(buf, 100, "%A", &t, __loc_);
+ strftime_l(buf, countof(buf), "%A", &t, __loc_);
__weeks_[i] = buf;
- strftime_l(buf, 100, "%a", &t, __loc_);
+ strftime_l(buf, countof(buf), "%a", &t, __loc_);
__weeks_[i+7] = buf;
}
// __months_
for (int i = 0; i < 12; ++i)
{
t.tm_mon = i;
- strftime_l(buf, 100, "%B", &t, __loc_);
+ strftime_l(buf, countof(buf), "%B", &t, __loc_);
__months_[i] = buf;
- strftime_l(buf, 100, "%b", &t, __loc_);
+ strftime_l(buf, countof(buf), "%b", &t, __loc_);
__months_[i+12] = buf;
}
// __am_pm_
t.tm_hour = 1;
- strftime_l(buf, 100, "%p", &t, __loc_);
+ strftime_l(buf, countof(buf), "%p", &t, __loc_);
__am_pm_[0] = buf;
t.tm_hour = 13;
- strftime_l(buf, 100, "%p", &t, __loc_);
+ strftime_l(buf, countof(buf), "%p", &t, __loc_);
__am_pm_[1] = buf;
__c_ = __analyze('c', ct);
__r_ = __analyze('r', ct);
@@ -4903,7 +4948,6 @@ __time_get_storage<wchar_t>::init(const ctype<wchar_t>& ct)
{
tm t = {0};
char buf[100];
- size_t be;
wchar_t wbuf[100];
wchar_t* wbe;
mbstate_t mb = {0};
@@ -4911,25 +4955,25 @@ __time_get_storage<wchar_t>::init(const ctype<wchar_t>& ct)
for (int i = 0; i < 7; ++i)
{
t.tm_wday = i;
- be = strftime_l(buf, 100, "%A", &t, __loc_);
+ 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, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
+ size_t j = mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);
#else
- size_t j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
+ size_t j = __mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);
#endif
if (j == size_t(-1))
__throw_runtime_error("locale not supported");
wbe = wbuf + j;
__weeks_[i].assign(wbuf, wbe);
- be = strftime_l(buf, 100, "%a", &t, __loc_);
+ strftime_l(buf, countof(buf), "%a", &t, __loc_);
mb = mbstate_t();
bb = buf;
#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
- j = mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
+ j = mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);
#else
- j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
+ j = __mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);
#endif
if (j == size_t(-1))
__throw_runtime_error("locale not supported");
@@ -4940,25 +4984,25 @@ __time_get_storage<wchar_t>::init(const ctype<wchar_t>& ct)
for (int i = 0; i < 12; ++i)
{
t.tm_mon = i;
- be = strftime_l(buf, 100, "%B", &t, __loc_);
+ 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, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
+ size_t j = mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);
#else
- size_t j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
+ size_t j = __mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);
#endif
if (j == size_t(-1))
__throw_runtime_error("locale not supported");
wbe = wbuf + j;
__months_[i].assign(wbuf, wbe);
- be = strftime_l(buf, 100, "%b", &t, __loc_);
+ strftime_l(buf, countof(buf), "%b", &t, __loc_);
mb = mbstate_t();
bb = buf;
#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
- j = mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
+ j = mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);
#else
- j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
+ j = __mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);
#endif
if (j == size_t(-1))
__throw_runtime_error("locale not supported");
@@ -4967,26 +5011,26 @@ __time_get_storage<wchar_t>::init(const ctype<wchar_t>& ct)
}
// __am_pm_
t.tm_hour = 1;
- be = strftime_l(buf, 100, "%p", &t, __loc_);
+ 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, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
+ size_t j = mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);
#else
- size_t j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
+ size_t j = __mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);
#endif
if (j == size_t(-1))
__throw_runtime_error("locale not supported");
wbe = wbuf + j;
__am_pm_[0].assign(wbuf, wbe);
t.tm_hour = 13;
- be = strftime_l(buf, 100, "%p", &t, __loc_);
+ strftime_l(buf, countof(buf), "%p", &t, __loc_);
mb = mbstate_t();
bb = buf;
#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
- j = mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
+ j = mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);
#else
- j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
+ j = __mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);
#endif
if (j == size_t(-1))
__throw_runtime_error("locale not supported");
@@ -5249,7 +5293,7 @@ __time_put::__do_put(char* __nb, char*& __ne, const tm* __tm,
char fmt[] = {'%', __fmt, __mod, 0};
if (__mod != 0)
swap(fmt[1], fmt[2]);
- size_t n = strftime_l(__nb, static_cast<size_t>(__ne-__nb), fmt, __tm, __loc_);
+ size_t n = strftime_l(__nb, countof(__nb, __ne), fmt, __tm, __loc_);
__ne = __nb + n;
}
@@ -5263,9 +5307,9 @@ __time_put::__do_put(wchar_t* __wb, wchar_t*& __we, const tm* __tm,
mbstate_t mb = {0};
const char* __nb = __nar;
#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
- size_t j = mbsrtowcs_l(__wb, &__nb, 100, &mb, __loc_);
+ size_t j = mbsrtowcs_l(__wb, &__nb, countof(__wb, __we), &mb, __loc_);
#else
- size_t j = __mbsrtowcs_l(__wb, &__nb, 100, &mb, __loc_);
+ size_t j = __mbsrtowcs_l(__wb, &__nb, countof(__wb, __we), &mb, __loc_);
#endif
if (j == size_t(-1))
__throw_runtime_error("locale not supported");
@@ -5788,9 +5832,9 @@ moneypunct_byname<wchar_t, false>::init(const char* nm)
mbstate_t mb = {0};
const char* bb = lc->currency_symbol;
#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
- size_t j = mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
+ size_t j = mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());
#else
- size_t j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
+ size_t j = __mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());
#endif
if (j == size_t(-1))
__throw_runtime_error("locale not supported");
@@ -5807,9 +5851,9 @@ 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, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
+ j = mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());
#else
- j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
+ j = __mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());
#endif
if (j == size_t(-1))
__throw_runtime_error("locale not supported");
@@ -5823,9 +5867,9 @@ 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, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
+ j = mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());
#else
- j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
+ j = __mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());
#endif
if (j == size_t(-1))
__throw_runtime_error("locale not supported");
@@ -5871,9 +5915,9 @@ moneypunct_byname<wchar_t, true>::init(const char* nm)
mbstate_t mb = {0};
const char* bb = lc->int_curr_symbol;
#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
- size_t j = mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
+ size_t j = mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());
#else
- size_t j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
+ size_t j = __mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());
#endif
if (j == size_t(-1))
__throw_runtime_error("locale not supported");
@@ -5894,9 +5938,9 @@ 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, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
+ j = mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());
#else
- j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
+ j = __mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());
#endif
if (j == size_t(-1))
__throw_runtime_error("locale not supported");
@@ -5914,9 +5958,9 @@ 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, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
+ j = mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());
#else
- j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
+ j = __mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());
#endif
if (j == size_t(-1))
__throw_runtime_error("locale not supported");