From 6f0342cf2e4802f6d7948e1c5f59c41b4e25789e Mon Sep 17 00:00:00 2001 From: Sean Hunt Date: Sat, 9 Jul 2011 03:40:04 +0000 Subject: [PATCH] Don't assume that wctype produces a nice mask on all platforms. On glibc, for instance, it's a const char *. git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@134787 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/__config | 4 ++++ src/locale.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/include/__config b/include/__config index 239f0a22c..a5afbcad7 100644 --- a/include/__config +++ b/include/__config @@ -289,4 +289,8 @@ template struct __static_assert_check {}; #define _LIBCPP_STABLE_APPLE_ABI #endif +#ifdef __APPLE__ +#define _LIBCPP_WCTYPE_IS_MASK +#endif + #endif // _LIBCPP_CONFIG diff --git a/src/locale.cpp b/src/locale.cpp index 63f54294a..561fd62e3 100644 --- a/src/locale.cpp +++ b/src/locale.cpp @@ -1114,7 +1114,21 @@ ctype_byname::~ctype_byname() bool ctype_byname::do_is(mask m, char_type c) const { +#ifdef _LIBCPP_WCTYPE_IS_MASK return static_cast(iswctype_l(c, m, __l)); +#else + 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; +#endif } const wchar_t* @@ -1154,8 +1168,24 @@ const wchar_t* ctype_byname::do_scan_is(mask m, const char_type* low, const char_type* high) const { for (; low != high; ++low) + { +#ifdef _LIBCPP_WCTYPE_IS_MASK 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; +#endif + } return low; } @@ -1163,8 +1193,24 @@ const wchar_t* ctype_byname::do_scan_not(mask m, const char_type* low, const char_type* high) const { for (; low != high; ++low) + { +#ifdef _LIBCPP_WCTYPE_IS_MASK 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; +#endif + } return low; }