summaryrefslogtreecommitdiffstats
path: root/contrib/libc++/src/locale.cpp
diff options
context:
space:
mode:
authordim <dim@FreeBSD.org>2013-04-27 22:47:52 +0000
committerdim <dim@FreeBSD.org>2013-04-27 22:47:52 +0000
commit815a6cc1e325a4e8596b91756039a7d699471b11 (patch)
treee5a6a26d0973c6968273f6fabb61cb3d624be555 /contrib/libc++/src/locale.cpp
parent1497a98f71419ff66d08ad2b8c90530e65521ac2 (diff)
downloadFreeBSD-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++/src/locale.cpp')
-rw-r--r--contrib/libc++/src/locale.cpp161
1 files changed, 98 insertions, 63 deletions
diff --git a/contrib/libc++/src/locale.cpp b/contrib/libc++/src/locale.cpp
index 53a8a4c..49c1cf2 100644
--- a/contrib/libc++/src/locale.cpp
+++ b/contrib/libc++/src/locale.cpp
@@ -25,13 +25,17 @@
#include "cstring"
#include "cwctype"
#include "__sso_allocator"
-#if _WIN32
+#ifdef _WIN32
#include <support/win32/locale_win32.h>
#else // _WIN32
#include <langinfo.h>
#endif // _!WIN32
#include <stdlib.h>
+// On Linux, wint_t and wchar_t have different signed-ness, and this causes
+// lots of noise in the build log, but no bugs that I know of.
+#pragma clang diagnostic ignored "-Wsign-conversion"
+
_LIBCPP_BEGIN_NAMESPACE_STD
#ifdef __cloc_defined
@@ -782,7 +786,7 @@ ctype<wchar_t>::do_toupper(char_type c) const
{
#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
return isascii(c) ? _DefaultRuneLocale.__mapupper[c] : c;
-#elif defined(__GLIBC__)
+#elif defined(__GLIBC__) || defined(EMSCRIPTEN)
return isascii(c) ? ctype<char>::__classic_upper_table()[c] : c;
#else
return (isascii(c) && iswlower_l(c, __cloc())) ? c-L'a'+L'A' : c;
@@ -795,7 +799,7 @@ ctype<wchar_t>::do_toupper(char_type* low, const char_type* high) const
for (; low != high; ++low)
#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
*low = isascii(*low) ? _DefaultRuneLocale.__mapupper[*low] : *low;
-#elif defined(__GLIBC__)
+#elif defined(__GLIBC__) || defined(EMSCRIPTEN)
*low = isascii(*low) ? ctype<char>::__classic_upper_table()[*low]
: *low;
#else
@@ -809,7 +813,7 @@ ctype<wchar_t>::do_tolower(char_type c) const
{
#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
return isascii(c) ? _DefaultRuneLocale.__maplower[c] : c;
-#elif defined(__GLIBC__)
+#elif defined(__GLIBC__) || defined(EMSCRIPTEN)
return isascii(c) ? ctype<char>::__classic_lower_table()[c] : c;
#else
return (isascii(c) && isupper_l(c, __cloc())) ? c-L'A'+'a' : c;
@@ -822,7 +826,7 @@ ctype<wchar_t>::do_tolower(char_type* low, const char_type* high) const
for (; low != high; ++low)
#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
*low = isascii(*low) ? _DefaultRuneLocale.__maplower[*low] : *low;
-#elif defined(__GLIBC__)
+#elif defined(__GLIBC__) || defined(EMSCRIPTEN)
*low = isascii(*low) ? ctype<char>::__classic_lower_table()[*low]
: *low;
#else
@@ -889,8 +893,9 @@ ctype<char>::do_toupper(char_type c) const
#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
return isascii(c) ?
static_cast<char>(_DefaultRuneLocale.__mapupper[static_cast<ptrdiff_t>(c)]) : c;
-#elif defined(__GLIBC__)
- return isascii(c) ? __classic_upper_table()[static_cast<size_t>(c)] : c;
+#elif defined(__GLIBC__) || defined(EMSCRIPTEN)
+ return isascii(c) ?
+ static_cast<char>(__classic_upper_table()[static_cast<size_t>(c)]) : c;
#else
return (isascii(c) && islower_l(c, __cloc())) ? c-'a'+'A' : c;
#endif
@@ -903,8 +908,9 @@ ctype<char>::do_toupper(char_type* low, const char_type* high) const
#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
*low = isascii(*low) ?
static_cast<char>(_DefaultRuneLocale.__mapupper[static_cast<ptrdiff_t>(*low)]) : *low;
-#elif defined(__GLIBC__)
- *low = isascii(*low) ? __classic_upper_table()[static_cast<size_t>(*low)] : *low;
+#elif defined(__GLIBC__) || defined(EMSCRIPTEN)
+ *low = isascii(*low) ?
+ static_cast<char>(__classic_upper_table()[static_cast<size_t>(*low)]) : *low;
#else
*low = (isascii(*low) && islower_l(*low, __cloc())) ? *low-'a'+'A' : *low;
#endif
@@ -917,8 +923,9 @@ ctype<char>::do_tolower(char_type c) const
#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
return isascii(c) ?
static_cast<char>(_DefaultRuneLocale.__maplower[static_cast<ptrdiff_t>(c)]) : c;
-#elif defined(__GLIBC__)
- return isascii(c) ? __classic_lower_table()[static_cast<size_t>(c)] : c;
+#elif defined(__GLIBC__) || defined(EMSCRIPTEN)
+ return isascii(c) ?
+ static_cast<char>(__classic_lower_table()[static_cast<size_t>(c)]) : c;
#else
return (isascii(c) && isupper_l(c, __cloc())) ? c-'A'+'a' : c;
#endif
@@ -930,8 +937,8 @@ ctype<char>::do_tolower(char_type* low, const char_type* high) const
for (; low != high; ++low)
#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()[static_cast<size_t>(*low)] : *low;
+#elif defined(__GLIBC__) || defined(EMSCRIPTEN)
+ *low = isascii(*low) ? static_cast<char>(__classic_lower_table()[static_cast<size_t>(*low)]) : *low;
#else
*low = (isascii(*low) && isupper_l(*low, __cloc())) ? *low-'A'+'a' : *low;
#endif
@@ -971,6 +978,12 @@ ctype<char>::do_narrow(const char_type* low, const char_type* high, char dfault,
return low;
}
+#ifdef EMSCRIPTEN
+extern "C" const unsigned short ** __ctype_b_loc();
+extern "C" const int ** __ctype_tolower_loc();
+extern "C" const int ** __ctype_toupper_loc();
+#endif
+
const ctype<char>::mask*
ctype<char>::classic_table() _NOEXCEPT
{
@@ -980,10 +993,12 @@ ctype<char>::classic_table() _NOEXCEPT
return __cloc()->__ctype_b;
#elif __sun__
return __ctype_mask;
-#elif _WIN32
+#elif defined(_WIN32)
return _ctype+1; // internal ctype mask table defined in msvcrt.dll
// This is assumed to be safe, which is a nonsense assumption because we're
// going to end up dereferencing it later...
+#elif defined(EMSCRIPTEN)
+ return *__ctype_b_loc();
#else
// Platform not supported: abort so the person doing the port knows what to
// fix
@@ -1007,6 +1022,20 @@ ctype<char>::__classic_upper_table() _NOEXCEPT
}
#endif // __GLIBC__
+#if defined(EMSCRIPTEN)
+const int*
+ctype<char>::__classic_lower_table() _NOEXCEPT
+{
+ return *__ctype_tolower_loc();
+}
+
+const int*
+ctype<char>::__classic_upper_table() _NOEXCEPT
+{
+ return *__ctype_toupper_loc();
+}
+#endif // EMSCRIPTEN
+
// template <> class ctype_byname<char>
ctype_byname<char>::ctype_byname(const char* name, size_t refs)
@@ -1100,16 +1129,17 @@ ctype_byname<wchar_t>::do_is(mask m, char_type c) const
return static_cast<bool>(iswctype_l(c, m, __l));
#else
bool result = false;
- if (m & space) result |= (iswspace_l(c, __l) != 0);
- if (m & print) result |= (iswprint_l(c, __l) != 0);
- if (m & cntrl) result |= (iswcntrl_l(c, __l) != 0);
- if (m & upper) result |= (iswupper_l(c, __l) != 0);
- if (m & lower) result |= (iswlower_l(c, __l) != 0);
- if (m & alpha) result |= (iswalpha_l(c, __l) != 0);
- if (m & digit) result |= (iswdigit_l(c, __l) != 0);
- if (m & punct) result |= (iswpunct_l(c, __l) != 0);
- if (m & xdigit) result |= (iswxdigit_l(c, __l) != 0);
- if (m & blank) result |= (iswblank_l(c, __l) != 0);
+ wint_t ch = static_cast<wint_t>(c);
+ if (m & space) result |= (iswspace_l(ch, __l) != 0);
+ if (m & print) result |= (iswprint_l(ch, __l) != 0);
+ if (m & cntrl) result |= (iswcntrl_l(ch, __l) != 0);
+ if (m & upper) result |= (iswupper_l(ch, __l) != 0);
+ if (m & lower) result |= (iswlower_l(ch, __l) != 0);
+ if (m & alpha) result |= (iswalpha_l(ch, __l) != 0);
+ if (m & digit) result |= (iswdigit_l(ch, __l) != 0);
+ if (m & punct) result |= (iswpunct_l(ch, __l) != 0);
+ if (m & xdigit) result |= (iswxdigit_l(ch, __l) != 0);
+ if (m & blank) result |= (iswblank_l(ch, __l) != 0);
return result;
#endif
}
@@ -1124,23 +1154,24 @@ ctype_byname<wchar_t>::do_is(const char_type* low, const char_type* high, mask*
else
{
*vec = 0;
- if (iswspace_l(*low, __l))
+ wint_t ch = static_cast<wint_t>(*low);
+ if (iswspace_l(ch, __l))
*vec |= space;
- if (iswprint_l(*low, __l))
+ if (iswprint_l(ch, __l))
*vec |= print;
- if (iswcntrl_l(*low, __l))
+ if (iswcntrl_l(ch, __l))
*vec |= cntrl;
- if (iswupper_l(*low, __l))
+ if (iswupper_l(ch, __l))
*vec |= upper;
- if (iswlower_l(*low, __l))
+ if (iswlower_l(ch, __l))
*vec |= lower;
- if (iswalpha_l(*low, __l))
+ if (iswalpha_l(ch, __l))
*vec |= alpha;
- if (iswdigit_l(*low, __l))
+ if (iswdigit_l(ch, __l))
*vec |= digit;
- if (iswpunct_l(*low, __l))
+ if (iswpunct_l(ch, __l))
*vec |= punct;
- if (iswxdigit_l(*low, __l))
+ if (iswxdigit_l(ch, __l))
*vec |= xdigit;
}
}
@@ -1156,16 +1187,17 @@ ctype_byname<wchar_t>::do_scan_is(mask m, const char_type* low, const char_type*
if (iswctype_l(*low, m, __l))
break;
#else
- if (m & space && iswspace_l(*low, __l)) break;
- if (m & print && iswprint_l(*low, __l)) break;
- if (m & cntrl && iswcntrl_l(*low, __l)) break;
- if (m & upper && iswupper_l(*low, __l)) break;
- if (m & lower && iswlower_l(*low, __l)) break;
- if (m & alpha && iswalpha_l(*low, __l)) break;
- if (m & digit && iswdigit_l(*low, __l)) break;
- if (m & punct && iswpunct_l(*low, __l)) break;
- if (m & xdigit && iswxdigit_l(*low, __l)) break;
- if (m & blank && iswblank_l(*low, __l)) break;
+ wint_t ch = static_cast<wint_t>(*low);
+ if (m & space && iswspace_l(ch, __l)) break;
+ if (m & print && iswprint_l(ch, __l)) break;
+ if (m & cntrl && iswcntrl_l(ch, __l)) break;
+ if (m & upper && iswupper_l(ch, __l)) break;
+ if (m & lower && iswlower_l(ch, __l)) break;
+ if (m & alpha && iswalpha_l(ch, __l)) break;
+ if (m & digit && iswdigit_l(ch, __l)) break;
+ if (m & punct && iswpunct_l(ch, __l)) break;
+ if (m & xdigit && iswxdigit_l(ch, __l)) break;
+ if (m & blank && iswblank_l(ch, __l)) break;
#endif
}
return low;
@@ -1180,16 +1212,17 @@ ctype_byname<wchar_t>::do_scan_not(mask m, const char_type* low, const char_type
if (!iswctype_l(*low, m, __l))
break;
#else
- if (m & space && iswspace_l(*low, __l)) continue;
- if (m & print && iswprint_l(*low, __l)) continue;
- if (m & cntrl && iswcntrl_l(*low, __l)) continue;
- if (m & upper && iswupper_l(*low, __l)) continue;
- if (m & lower && iswlower_l(*low, __l)) continue;
- if (m & alpha && iswalpha_l(*low, __l)) continue;
- if (m & digit && iswdigit_l(*low, __l)) continue;
- if (m & punct && iswpunct_l(*low, __l)) continue;
- if (m & xdigit && iswxdigit_l(*low, __l)) continue;
- if (m & blank && iswblank_l(*low, __l)) continue;
+ wint_t ch = static_cast<wint_t>(*low);
+ if (m & space && iswspace_l(ch, __l)) continue;
+ if (m & print && iswprint_l(ch, __l)) continue;
+ if (m & cntrl && iswcntrl_l(ch, __l)) continue;
+ if (m & upper && iswupper_l(ch, __l)) continue;
+ if (m & lower && iswlower_l(ch, __l)) continue;
+ if (m & alpha && iswalpha_l(ch, __l)) continue;
+ if (m & digit && iswdigit_l(ch, __l)) continue;
+ if (m & punct && iswpunct_l(ch, __l)) continue;
+ if (m & xdigit && iswxdigit_l(ch, __l)) continue;
+ if (m & blank && iswblank_l(ch, __l)) continue;
break;
#endif
}
@@ -1374,7 +1407,7 @@ codecvt<wchar_t, char, mbstate_t>::do_out(state_type& st,
to_nxt = to;
for (frm_nxt = frm; frm != frm_end && to != to_end; frm = frm_nxt, to = to_nxt)
{
- // save state in case needed to reover to_nxt on error
+ // 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),
@@ -1443,7 +1476,7 @@ codecvt<wchar_t, char, mbstate_t>::do_in(state_type& st,
to_nxt = to;
for (frm_nxt = frm; frm != frm_end && to != to_end; frm = frm_nxt, to = to_nxt)
{
- // save state in case needed to reover to_nxt on error
+ // 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),
@@ -1589,9 +1622,9 @@ int
codecvt<wchar_t, char, mbstate_t>::do_max_length() const _NOEXCEPT
{
#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
- return __l == 0 ? 1 : MB_CUR_MAX_L(__l);
+ return __l == 0 ? 1 : static_cast<int>( MB_CUR_MAX_L(__l));
#else
- return __l == 0 ? 1 : __mb_cur_max_l(__l);
+ return __l == 0 ? 1 : static_cast<int>(__mb_cur_max_l(__l));
#endif
}
@@ -5768,7 +5801,7 @@ moneypunct_byname<char, true>::init(const char* nm)
__frac_digits_ = lc->int_frac_digits;
else
__frac_digits_ = base::do_frac_digits();
-#if _WIN32
+#ifdef _WIN32
if (lc->p_sign_posn == 0)
#else // _WIN32
if (lc->int_p_sign_posn == 0)
@@ -5776,7 +5809,7 @@ moneypunct_byname<char, true>::init(const char* nm)
__positive_sign_ = "()";
else
__positive_sign_ = lc->positive_sign;
-#if _WIN32
+#ifdef _WIN32
if(lc->n_sign_posn == 0)
#else // _WIN32
if (lc->int_n_sign_posn == 0)
@@ -5788,7 +5821,7 @@ moneypunct_byname<char, true>::init(const char* nm)
// the same places in curr_symbol since there's no way to
// represent anything else.
string_type __dummy_curr_symbol = __curr_symbol_;
-#if _WIN32
+#ifdef _WIN32
__init_pat(__pos_format_, __dummy_curr_symbol, true,
lc->p_cs_precedes, lc->p_sep_by_space, lc->p_sign_posn, ' ');
__init_pat(__neg_format_, __curr_symbol_, true,
@@ -5927,7 +5960,7 @@ moneypunct_byname<wchar_t, true>::init(const char* nm)
__frac_digits_ = lc->int_frac_digits;
else
__frac_digits_ = base::do_frac_digits();
-#if _WIN32
+#ifdef _WIN32
if (lc->p_sign_posn == 0)
#else // _WIN32
if (lc->int_p_sign_posn == 0)
@@ -5947,7 +5980,7 @@ moneypunct_byname<wchar_t, true>::init(const char* nm)
wbe = wbuf + j;
__positive_sign_.assign(wbuf, wbe);
}
-#if _WIN32
+#ifdef _WIN32
if (lc->n_sign_posn == 0)
#else // _WIN32
if (lc->int_n_sign_posn == 0)
@@ -5971,7 +6004,7 @@ moneypunct_byname<wchar_t, true>::init(const char* nm)
// the same places in curr_symbol since there's no way to
// represent anything else.
string_type __dummy_curr_symbol = __curr_symbol_;
-#if _WIN32
+#ifdef _WIN32
__init_pat(__pos_format_, __dummy_curr_symbol, true,
lc->p_cs_precedes, lc->p_sep_by_space, lc->p_sign_posn, L' ');
__init_pat(__neg_format_, __curr_symbol_, true,
@@ -5992,6 +6025,8 @@ void __throw_runtime_error(const char* msg)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
throw runtime_error(msg);
+#else
+ (void)msg;
#endif
}
OpenPOWER on IntegriCloud