aboutsummaryrefslogtreecommitdiff
path: root/system/lib/libcxx/locale.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'system/lib/libcxx/locale.cpp')
-rw-r--r--system/lib/libcxx/locale.cpp984
1 files changed, 603 insertions, 381 deletions
diff --git a/system/lib/libcxx/locale.cpp b/system/lib/libcxx/locale.cpp
index 87c47636..21497903 100644
--- a/system/lib/libcxx/locale.cpp
+++ b/system/lib/libcxx/locale.cpp
@@ -7,6 +7,12 @@
//
//===----------------------------------------------------------------------===//
+// On Solaris, we need to define something to make the C99 parts of localeconv
+// visible.
+#ifdef __sun__
+#define _LCONV_C99
+#endif
+
#include "string"
#include "locale"
#include "codecvt"
@@ -20,38 +26,27 @@
#include "cwctype"
#include "__sso_allocator"
#if _WIN32
-#include <locale.h>
+#include <support/win32/locale_win32.h>
#else // _WIN32
#include <langinfo.h>
#endif // _!WIN32
#include <stdlib.h>
-#ifdef _LIBCPP_STABLE_APPLE_ABI
-namespace {
- decltype(MB_CUR_MAX_L(_VSTD::declval<locale_t>()))
- inline _LIBCPP_INLINE_VISIBILITY
- mb_cur_max_l(locale_t loc)
- {
- return MB_CUR_MAX_L(loc);
- }
-}
-#endif
+// 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
-#ifndef _LIBCPP_STABLE_APPLE_ABI
+#ifdef __cloc_defined
locale_t __cloc() {
// In theory this could create a race condition. In practice
// the race condition is non-fatal since it will just create
// a little resource leak. Better approach would be appreciated.
-#ifdef __APPLE__
- return 0;
-#else
static locale_t result = newlocale(LC_ALL_MASK, "C", 0);
return result;
-#endif
}
-#endif // _LIBCPP_STABLE_APPLE_ABI
+#endif // __cloc_defined
namespace {
@@ -90,14 +85,44 @@ 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"
+
class _LIBCPP_HIDDEN locale::__imp
: public facet
{
enum {N = 28};
- string name_;
vector<facet*, __sso_allocator<facet*, N> > facets_;
+ string name_;
public:
explicit __imp(size_t refs = 0);
explicit __imp(const string& name, size_t refs = 0);
@@ -108,7 +133,8 @@ public:
~__imp();
const string& name() const {return name_;}
- bool has_facet(long id) const {return id < facets_.size() && facets_[id];}
+ bool has_facet(long id) const
+ {return static_cast<size_t>(id) < facets_.size() && facets_[static_cast<size_t>(id)];}
const locale::facet* use_facet(long id) const;
static const locale& make_classic();
@@ -119,46 +145,48 @@ private:
template <class F> void install_from(const __imp& other);
};
+#pragma clang diagnostic pop
+
locale::__imp::__imp(size_t refs)
: facet(refs),
- name_("C"),
- facets_(N)
+ facets_(N),
+ name_("C")
{
facets_.clear();
- install(&make<_VSTD::collate<char> >(1));
- install(&make<_VSTD::collate<wchar_t> >(1));
- install(&make<_VSTD::ctype<char> >((ctype_base::mask*)0, false, 1));
- install(&make<_VSTD::ctype<wchar_t> >(1));
- install(&make<codecvt<char, char, mbstate_t> >(1));
- install(&make<codecvt<wchar_t, char, mbstate_t> >(1));
- install(&make<codecvt<char16_t, char, mbstate_t> >(1));
- install(&make<codecvt<char32_t, char, mbstate_t> >(1));
- install(&make<numpunct<char> >(1));
- install(&make<numpunct<wchar_t> >(1));
- install(&make<num_get<char> >(1));
- install(&make<num_get<wchar_t> >(1));
- install(&make<num_put<char> >(1));
- install(&make<num_put<wchar_t> >(1));
- install(&make<moneypunct<char, false> >(1));
- install(&make<moneypunct<char, true> >(1));
- install(&make<moneypunct<wchar_t, false> >(1));
- install(&make<moneypunct<wchar_t, true> >(1));
- install(&make<money_get<char> >(1));
- install(&make<money_get<wchar_t> >(1));
- install(&make<money_put<char> >(1));
- install(&make<money_put<wchar_t> >(1));
- install(&make<time_get<char> >(1));
- install(&make<time_get<wchar_t> >(1));
- install(&make<time_put<char> >(1));
- install(&make<time_put<wchar_t> >(1));
- install(&make<_VSTD::messages<char> >(1));
- install(&make<_VSTD::messages<wchar_t> >(1));
+ install(&make<_VSTD::collate<char> >(1u));
+ install(&make<_VSTD::collate<wchar_t> >(1u));
+ install(&make<_VSTD::ctype<char> >((ctype_base::mask*)0, false, 1u));
+ install(&make<_VSTD::ctype<wchar_t> >(1u));
+ install(&make<codecvt<char, char, mbstate_t> >(1u));
+ install(&make<codecvt<wchar_t, char, mbstate_t> >(1u));
+ install(&make<codecvt<char16_t, char, mbstate_t> >(1u));
+ install(&make<codecvt<char32_t, char, mbstate_t> >(1u));
+ install(&make<numpunct<char> >(1u));
+ install(&make<numpunct<wchar_t> >(1u));
+ install(&make<num_get<char> >(1u));
+ install(&make<num_get<wchar_t> >(1u));
+ install(&make<num_put<char> >(1u));
+ install(&make<num_put<wchar_t> >(1u));
+ install(&make<moneypunct<char, false> >(1u));
+ install(&make<moneypunct<char, true> >(1u));
+ install(&make<moneypunct<wchar_t, false> >(1u));
+ install(&make<moneypunct<wchar_t, true> >(1u));
+ install(&make<money_get<char> >(1u));
+ install(&make<money_get<wchar_t> >(1u));
+ install(&make<money_put<char> >(1u));
+ install(&make<money_put<wchar_t> >(1u));
+ install(&make<time_get<char> >(1u));
+ install(&make<time_get<wchar_t> >(1u));
+ install(&make<time_put<char> >(1u));
+ install(&make<time_put<wchar_t> >(1u));
+ install(&make<_VSTD::messages<char> >(1u));
+ install(&make<_VSTD::messages<wchar_t> >(1u));
}
locale::__imp::__imp(const string& name, size_t refs)
: facet(refs),
- name_(name),
- facets_(N)
+ facets_(N),
+ name_(name)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
try
@@ -200,9 +228,14 @@ 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)
- : name_(other.name_),
- facets_(max<size_t>(N, other.facets_.size()))
+ : facets_(max<size_t>(N, other.facets_.size())),
+ name_(other.name_)
{
facets_ = other.facets_;
for (unsigned i = 0; i < facets_.size(); ++i)
@@ -210,9 +243,11 @@ 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)
- : name_("*"),
- facets_(N)
+ : facets_(N),
+ name_("*")
{
facets_ = other.facets_;
for (unsigned i = 0; i < facets_.size(); ++i)
@@ -282,8 +317,8 @@ locale::__imp::install_from(const locale::__imp& one)
}
locale::__imp::__imp(const __imp& other, const __imp& one, locale::category c)
- : name_("*"),
- facets_(N)
+ : facets_(N),
+ name_("*")
{
facets_ = other.facets_;
for (unsigned i = 0; i < facets_.size(); ++i)
@@ -352,8 +387,8 @@ locale::__imp::__imp(const __imp& other, const __imp& one, locale::category c)
}
locale::__imp::__imp(const __imp& other, facet* f, long id)
- : name_("*"),
- facets_(max<size_t>(N, other.facets_.size()+1))
+ : facets_(max<size_t>(N, other.facets_.size()+1)),
+ name_("*")
{
f->__add_shared();
unique_ptr<facet, release> hold(f);
@@ -376,11 +411,11 @@ locale::__imp::install(facet* f, long id)
{
f->__add_shared();
unique_ptr<facet, release> hold(f);
- if (id >= facets_.size())
- facets_.resize(id+1);
- if (facets_[id])
- facets_[id]->__release_shared();
- facets_[id] = hold.release();
+ if (static_cast<size_t>(id) >= facets_.size())
+ facets_.resize(static_cast<size_t>(id+1));
+ if (facets_[static_cast<size_t>(id)])
+ facets_[static_cast<size_t>(id)]->__release_shared();
+ facets_[static_cast<size_t>(id)] = hold.release();
}
const locale::facet*
@@ -390,7 +425,7 @@ locale::__imp::use_facet(long id) const
if (!has_facet(id))
throw bad_cast();
#endif // _LIBCPP_NO_EXCEPTIONS
- return facets_[id];
+ return facets_[static_cast<size_t>(id)];
}
// locale
@@ -401,7 +436,7 @@ locale::__imp::make_classic()
// only one thread can get in here and it only gets in once
static aligned_storage<sizeof(locale)>::type buf;
locale* c = (locale*)&buf;
- c->__locale_ = &make<__imp>(1);
+ c->__locale_ = &make<__imp>(1u);
return *c;
}
@@ -417,7 +452,6 @@ locale::__imp::make_global()
{
// only one thread can get in here and it only gets in once
static aligned_storage<sizeof(locale)>::type buf;
- locale* g = (locale*)&buf;
::new (&buf) locale(locale::classic());
return *(locale*)&buf;
}
@@ -695,6 +729,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()
@@ -737,10 +784,12 @@ ctype<wchar_t>::do_scan_not(mask m, const char_type* low, const char_type* high)
wchar_t
ctype<wchar_t>::do_toupper(char_type c) const
{
-#if !(defined(_LIBCPP_STABLE_APPLE_ABI) || defined(__FreeBSD__))
+#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
+ return isascii(c) ? _DefaultRuneLocale.__mapupper[c] : c;
+#elif defined(__GLIBC__)
return isascii(c) ? ctype<char>::__classic_upper_table()[c] : c;
#else
- return isascii(c) ? _DefaultRuneLocale.__mapupper[c] : c;
+ return (isascii(c) && iswlower_l(c, __cloc())) ? c-L'a'+L'A' : c;
#endif
}
@@ -748,11 +797,13 @@ const wchar_t*
ctype<wchar_t>::do_toupper(char_type* low, const char_type* high) const
{
for (; low != high; ++low)
-#if !(defined(_LIBCPP_STABLE_APPLE_ABI) || defined(__FreeBSD__))
+#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
+ *low = isascii(*low) ? _DefaultRuneLocale.__mapupper[*low] : *low;
+#elif defined(__GLIBC__)
*low = isascii(*low) ? ctype<char>::__classic_upper_table()[*low]
: *low;
#else
- *low = isascii(*low) ? _DefaultRuneLocale.__mapupper[*low] : *low;
+ *low = (isascii(*low) && islower_l(*low, __cloc())) ? (*low-L'a'+L'A') : *low;
#endif
return low;
}
@@ -760,10 +811,12 @@ ctype<wchar_t>::do_toupper(char_type* low, const char_type* high) const
wchar_t
ctype<wchar_t>::do_tolower(char_type c) const
{
-#ifndef _LIBCPP_STABLE_APPLE_ABI
+#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
+ return isascii(c) ? _DefaultRuneLocale.__maplower[c] : c;
+#elif defined(__GLIBC__)
return isascii(c) ? ctype<char>::__classic_lower_table()[c] : c;
#else
- return isascii(c) ? _DefaultRuneLocale.__maplower[c] : c;
+ return (isascii(c) && isupper_l(c, __cloc())) ? c-L'A'+'a' : c;
#endif
}
@@ -771,11 +824,13 @@ const wchar_t*
ctype<wchar_t>::do_tolower(char_type* low, const char_type* high) const
{
for (; low != high; ++low)
-#ifndef _LIBCPP_STABLE_APPLE_ABI
+#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
+ *low = isascii(*low) ? _DefaultRuneLocale.__maplower[*low] : *low;
+#elif defined(__GLIBC__)
*low = isascii(*low) ? ctype<char>::__classic_lower_table()[*low]
: *low;
#else
- *low = isascii(*low) ? _DefaultRuneLocale.__maplower[*low] : *low;
+ *low = (isascii(*low) && isupper_l(*low, __cloc())) ? *low-L'A'+L'a' : *low;
#endif
return low;
}
@@ -807,7 +862,7 @@ ctype<wchar_t>::do_narrow(const char_type* low, const char_type* high, char dfau
{
for (; low != high; ++low, ++dest)
if (isascii(*low))
- *dest = *low;
+ *dest = static_cast<char>(*low);
else
*dest = dfault;
return low;
@@ -835,10 +890,14 @@ ctype<char>::~ctype()
char
ctype<char>::do_toupper(char_type c) const
{
-#ifndef _LIBCPP_STABLE_APPLE_ABI
- return isascii(c) ? __classic_upper_table()[c] : c;
+#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
+ return isascii(c) ?
+ static_cast<char>(_DefaultRuneLocale.__mapupper[static_cast<ptrdiff_t>(c)]) : c;
+#elif defined(__GLIBC__)
+ return isascii(c) ?
+ static_cast<char>(__classic_upper_table()[static_cast<size_t>(c)]) : c;
#else
- return isascii(c) ? _DefaultRuneLocale.__mapupper[c] : c;
+ return (isascii(c) && islower_l(c, __cloc())) ? c-'a'+'A' : c;
#endif
}
@@ -846,10 +905,14 @@ const char*
ctype<char>::do_toupper(char_type* low, const char_type* high) const
{
for (; low != high; ++low)
-#ifndef _LIBCPP_STABLE_APPLE_ABI
- *low = isascii(*low) ? __classic_upper_table()[*low] : *low;
+#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
+ *low = isascii(*low) ?
+ static_cast<char>(_DefaultRuneLocale.__mapupper[static_cast<ptrdiff_t>(*low)]) : *low;
+#elif defined(__GLIBC__)
+ *low = isascii(*low) ?
+ static_cast<char>(__classic_upper_table()[static_cast<size_t>(*low)]) : *low;
#else
- *low = isascii(*low) ? _DefaultRuneLocale.__mapupper[*low] : *low;
+ *low = (isascii(*low) && islower_l(*low, __cloc())) ? *low-'a'+'A' : *low;
#endif
return low;
}
@@ -857,10 +920,14 @@ ctype<char>::do_toupper(char_type* low, const char_type* high) const
char
ctype<char>::do_tolower(char_type c) const
{
-#ifndef _LIBCPP_STABLE_APPLE_ABI
- return isascii(c) ? __classic_lower_table()[c] : c;
+#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
+ return isascii(c) ?
+ static_cast<char>(_DefaultRuneLocale.__maplower[static_cast<ptrdiff_t>(c)]) : c;
+#elif defined(__GLIBC__)
+ return isascii(c) ?
+ static_cast<char>(__classic_lower_table()[static_cast<size_t>(c)]) : c;
#else
- return isascii(c) ? _DefaultRuneLocale.__maplower[c] : c;
+ return (isascii(c) && isupper_l(c, __cloc())) ? c-'A'+'a' : c;
#endif
}
@@ -868,10 +935,12 @@ const char*
ctype<char>::do_tolower(char_type* low, const char_type* high) const
{
for (; low != high; ++low)
-#ifndef _LIBCPP_STABLE_APPLE_ABI
- *low = isascii(*low) ? __classic_lower_table()[*low] : *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) ? static_cast<char>(__classic_lower_table()[static_cast<size_t>(*low)]) : *low;
#else
- *low = isascii(*low) ? _DefaultRuneLocale.__maplower[*low] : *low;
+ *low = (isascii(*low) && isupper_l(*low, __cloc())) ? *low-'A'+'a' : *low;
#endif
return low;
}
@@ -909,11 +978,6 @@ ctype<char>::do_narrow(const char_type* low, const char_type* high, char dfault,
return low;
}
-// XXX Emscripten define local table
-extern "C" const unsigned short ** __ctype_b_loc();
-extern "C" const int ** __ctype_tolower_loc();
-extern "C" const int ** __ctype_toupper_loc();
-
const ctype<char>::mask*
ctype<char>::classic_table() _NOEXCEPT
{
@@ -921,44 +985,34 @@ ctype<char>::classic_table() _NOEXCEPT
return _DefaultRuneLocale.__runetype;
#elif defined(__GLIBC__)
return __cloc()->__ctype_b;
+#elif __sun__
+ return __ctype_mask;
+#elif _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
+# warning ctype<char>::classic_table() is not implemented
+ abort();
return NULL;
#endif
}
-#ifndef _LIBCPP_STABLE_APPLE_ABI
+#if defined(__GLIBC__)
const int*
ctype<char>::__classic_lower_table() _NOEXCEPT
{
-#if defined(__APPLE__) || defined(__FreeBSD__)
- return _DefaultRuneLocale.__maplower;
-#elif defined(__GLIBC__)
return __cloc()->__ctype_tolower;
-#elif defined(EMSCRIPTEN)
- return *__ctype_tolower_loc();
-#else
- return NULL;
-#endif
}
const int*
ctype<char>::__classic_upper_table() _NOEXCEPT
{
-#if defined(__APPLE__) || defined(__FreeBSD__)
- return _DefaultRuneLocale.__mapupper;
-#elif defined(__GLIBC__)
return __cloc()->__ctype_toupper;
-#elif defined(EMSCRIPTEN)
- return *__ctype_toupper_loc();
-#else
- return NULL;
-#endif
}
-#endif // _LIBCPP_STABLE_APPLE_ABI
+#endif // __GLIBC__
// template <> class ctype_byname<char>
@@ -992,28 +1046,28 @@ ctype_byname<char>::~ctype_byname()
char
ctype_byname<char>::do_toupper(char_type c) const
{
- return toupper_l(c, __l);
+ return static_cast<char>(toupper_l(c, __l));
}
const char*
ctype_byname<char>::do_toupper(char_type* low, const char_type* high) const
{
for (; low != high; ++low)
- *low = toupper_l(*low, __l);
+ *low = static_cast<char>(toupper_l(*low, __l));
return low;
}
char
ctype_byname<char>::do_tolower(char_type c) const
{
- return tolower_l(c, __l);
+ return static_cast<char>(tolower_l(c, __l));
}
const char*
ctype_byname<char>::do_tolower(char_type* low, const char_type* high) const
{
for (; low != high; ++low)
- *low = tolower_l(*low, __l);
+ *low = static_cast<char>(tolower_l(*low, __l));
return low;
}
@@ -1052,18 +1106,19 @@ ctype_byname<wchar_t>::do_is(mask m, char_type c) const
#ifdef _LIBCPP_WCTYPE_IS_MASK
return static_cast<bool>(iswctype_l(c, m, __l));
#else
- // FIXME: This is broken for things that test more than one flag.
- if (m & space && !iswspace_l(c, __l)) return false;
- if (m & print && !iswprint_l(c, __l)) return false;
- if (m & cntrl && !iswcntrl_l(c, __l)) return false;
- if (m & upper && !iswupper_l(c, __l)) return false;
- if (m & lower && !iswlower_l(c, __l)) return false;
- if (m & alpha && !iswalpha_l(c, __l)) return false;
- if (m & digit && !iswdigit_l(c, __l)) return false;
- if (m & punct && !iswpunct_l(c, __l)) return false;
- if (m & xdigit && !iswxdigit_l(c, __l)) return false;
- if (m & blank && !iswblank_l(c, __l)) return false;
- return true;
+ bool result = false;
+ 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
}
@@ -1077,23 +1132,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;
}
}
@@ -1109,17 +1165,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)) 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;
- 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;
@@ -1134,16 +1190,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
}
@@ -1181,7 +1238,7 @@ 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_STABLE_APPLE_ABI
+#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
return btowc_l(c, __l);
#else
return __btowc_l(c, __l);
@@ -1192,7 +1249,7 @@ 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_STABLE_APPLE_ABI
+#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
*dest = btowc_l(*low, __l);
#else
*dest = __btowc_l(*low, __l);
@@ -1203,12 +1260,12 @@ ctype_byname<wchar_t>::do_widen(const char* low, const char* high, char_type* de
char
ctype_byname<wchar_t>::do_narrow(char_type c, char dfault) const
{
-#ifdef _LIBCPP_STABLE_APPLE_ABI
+#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
int r = wctob_l(c, __l);
#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*
@@ -1216,12 +1273,12 @@ ctype_byname<wchar_t>::do_narrow(const char_type* low, const char_type* high, ch
{
for (; low != high; ++low, ++dest)
{
-#ifdef _LIBCPP_STABLE_APPLE_ABI
+#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
int r = wctob_l(*low, __l);
#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;
}
@@ -1278,7 +1335,7 @@ int
codecvt<char, char, mbstate_t>::do_length(state_type&,
const extern_type* frm, const extern_type* end, size_t mx) const
{
- return static_cast<int>(min<size_t>(mx, end-frm));
+ return static_cast<int>(min<size_t>(mx, static_cast<size_t>(end-frm)));
}
int
@@ -1330,8 +1387,9 @@ codecvt<wchar_t, char, mbstate_t>::do_out(state_type& st,
{
// save state in case needed to reover to_nxt on error
mbstate_t save_state = st;
-#ifdef _LIBCPP_STABLE_APPLE_ABI
- size_t n = wcsnrtombs_l(to, &frm_nxt, fend-frm, to_end-to, &st, __l);
+#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
@@ -1340,7 +1398,7 @@ codecvt<wchar_t, char, mbstate_t>::do_out(state_type& st,
// need to recover to_nxt
for (to_nxt = to; frm != frm_nxt; ++frm)
{
-#ifdef _LIBCPP_STABLE_APPLE_ABI
+#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
n = wcrtomb_l(to_nxt, *frm, &save_state, __l);
#else
n = __wcrtomb_l(to_nxt, *frm, &save_state, __l);
@@ -1361,14 +1419,14 @@ 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_STABLE_APPLE_ABI
+#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
n = wcrtomb_l(tmp, intern_type(), &st, __l);
#else
n = __wcrtomb_l(tmp, intern_type(), &st, __l);
#endif
if (n == size_t(-1)) // on error
return error;
- if (n > to_end-to_nxt) // is there room?
+ if (n > static_cast<size_t>(to_end-to_nxt)) // is there room?
return partial;
for (extern_type* p = tmp; n; --n) // write it
*to_nxt++ = *p++;
@@ -1398,8 +1456,9 @@ codecvt<wchar_t, char, mbstate_t>::do_in(state_type& st,
{
// save state in case needed to reover to_nxt on error
mbstate_t save_state = st;
-#ifdef _LIBCPP_STABLE_APPLE_ABI
- size_t n = mbsnrtowcs_l(to, &frm_nxt, fend-frm, to_end-to, &st, __l);
+#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
@@ -1408,8 +1467,9 @@ codecvt<wchar_t, char, mbstate_t>::do_in(state_type& st,
// need to recover to_nxt
for (to_nxt = to; frm != frm_nxt; ++to_nxt)
{
-#ifdef _LIBCPP_STABLE_APPLE_ABI
- n = mbrtowc_l(to_nxt, frm, fend-frm, &save_state, __l);
+#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
@@ -1418,10 +1478,10 @@ codecvt<wchar_t, char, mbstate_t>::do_in(state_type& st,
case 0:
++frm;
break;
- case static_cast<size_t>(-1): // XXX EMSCRIPTEN
+ case size_t(-1):
frm_nxt = frm;
return error;
- case static_cast<size_t>(-2): // XXX EMSCRIPTEN
+ case size_t(-2):
frm_nxt = frm;
return partial;
default:
@@ -1440,7 +1500,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_STABLE_APPLE_ABI
+#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);
@@ -1464,7 +1524,7 @@ codecvt<wchar_t, char, mbstate_t>::do_unshift(state_type& st,
{
to_nxt = to;
extern_type tmp[MB_LEN_MAX];
-#ifdef _LIBCPP_STABLE_APPLE_ABI
+#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);
@@ -1472,7 +1532,7 @@ codecvt<wchar_t, char, mbstate_t>::do_unshift(state_type& st,
if (n == size_t(-1) || n == 0) // on error
return error;
--n;
- if (n > to_end-to_nxt) // is there room?
+ if (n > static_cast<size_t>(to_end-to_nxt)) // is there room?
return partial;
for (extern_type* p = tmp; n; --n) // write it
*to_nxt++ = *p++;
@@ -1482,14 +1542,14 @@ codecvt<wchar_t, char, mbstate_t>::do_unshift(state_type& st,
int
codecvt<wchar_t, char, mbstate_t>::do_encoding() const _NOEXCEPT
{
-#ifdef _LIBCPP_STABLE_APPLE_ABI
+#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
if (mbtowc_l((wchar_t*) 0, (const char*) 0, MB_LEN_MAX, __l) == 0)
#else
if (__mbtowc_l((wchar_t*) 0, (const char*) 0, MB_LEN_MAX, __l) == 0)
#endif
{
// stateless encoding
-#ifdef _LIBCPP_STABLE_APPLE_ABI
+#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
@@ -1513,8 +1573,8 @@ 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_STABLE_APPLE_ABI
- size_t n = mbrlen_l(frm, frm_end-frm, &st, __l);
+#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
@@ -1524,8 +1584,8 @@ codecvt<wchar_t, char, mbstate_t>::do_length(state_type& st,
++nbytes;
++frm;
break;
- case static_cast<size_t>(-1): // XXX EMSCRIPTEN
- case static_cast<size_t>(-2): // XXX EMSCRIPTEN
+ case size_t(-1):
+ case size_t(-2):
return nbytes;
default:
nbytes += n;
@@ -1539,10 +1599,10 @@ 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_STABLE_APPLE_ABI
- return __l == 0 ? 1 : MB_CUR_MAX_L(__l);
+#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
+ 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
}
@@ -1997,9 +2057,6 @@ utf8_to_utf16_length(const uint8_t* frm, const uint8_t* frm_end,
break;
uint8_t c2 = frm_nxt[1];
uint8_t c3 = frm_nxt[2];
- uint16_t t = static_cast<uint16_t>(((c1 & 0x0F) << 12)
- | ((c2 & 0x3F) << 6)
- | (c3 & 0x3F));
switch (c1)
{
case 0xE0:
@@ -2017,7 +2074,7 @@ utf8_to_utf16_length(const uint8_t* frm, const uint8_t* frm_end,
}
if ((c3 & 0xC0) != 0x80)
break;
- if ((((c1 & 0x0F) << 12) | ((c2 & 0x3F) << 6) | (c3 & 0x3F)) > Maxcode)
+ if ((((c1 & 0x0Fu) << 12) | ((c2 & 0x3Fu) << 6) | (c3 & 0x3Fu)) > Maxcode)
break;
frm_nxt += 3;
}
@@ -2259,7 +2316,7 @@ utf8_to_ucs4_length(const uint8_t* frm, const uint8_t* frm_end,
{
if ((frm_end-frm_nxt < 2) || ((frm_nxt[1] & 0xC0) != 0x80))
break;
- if ((((c1 & 0x1F) << 6) | (frm_nxt[1] & 0x3F)) > Maxcode)
+ if ((((c1 & 0x1Fu) << 6) | (frm_nxt[1] & 0x3Fu)) > Maxcode)
break;
frm_nxt += 2;
}
@@ -2286,7 +2343,7 @@ utf8_to_ucs4_length(const uint8_t* frm, const uint8_t* frm_end,
}
if ((c3 & 0xC0) != 0x80)
break;
- if ((((c1 & 0x0F) << 12) | ((c2 & 0x3F) << 6) | (c3 & 0x3F)) > Maxcode)
+ if ((((c1 & 0x0Fu) << 12) | ((c2 & 0x3Fu) << 6) | (c3 & 0x3Fu)) > Maxcode)
break;
frm_nxt += 3;
}
@@ -2314,12 +2371,8 @@ utf8_to_ucs4_length(const uint8_t* frm, const uint8_t* frm_end,
}
if ((c3 & 0xC0) != 0x80 || (c4 & 0xC0) != 0x80)
break;
- uint32_t t = static_cast<uint32_t>(((c1 & 0x07) << 18)
- | ((c2 & 0x3F) << 12)
- | ((c3 & 0x3F) << 6)
- | (c4 & 0x3F));
- if ((((c1 & 0x07) << 18) | ((c2 & 0x3F) << 12) |
- ((c3 & 0x3F) << 6) | (c4 & 0x3F)) > Maxcode)
+ if ((((c1 & 0x07u) << 18) | ((c2 & 0x3Fu) << 12) |
+ ((c3 & 0x3Fu) << 6) | (c4 & 0x3Fu)) > Maxcode)
break;
frm_nxt += 4;
}
@@ -2488,7 +2541,7 @@ utf8_to_ucs2_length(const uint8_t* frm, const uint8_t* frm_end,
{
if ((frm_end-frm_nxt < 2) || ((frm_nxt[1] & 0xC0) != 0x80))
break;
- if ((((c1 & 0x1F) << 6) | (frm_nxt[1] & 0x3F)) > Maxcode)
+ if ((((c1 & 0x1Fu) << 6) | (frm_nxt[1] & 0x3Fu)) > Maxcode)
br