Skip to content

Commit 0081892

Browse files
committed
Don't assume that wctype produces a nice mask on all platforms. On
glibc, for instance, it's a const char *. llvm-svn: 134787
1 parent 7eb661e commit 0081892

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

libcxx/include/__config

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,4 +289,8 @@ template <unsigned> struct __static_assert_check {};
289289
#define _LIBCPP_STABLE_APPLE_ABI
290290
#endif
291291

292+
#ifdef __APPLE__
293+
#define _LIBCPP_WCTYPE_IS_MASK
294+
#endif
295+
292296
#endif // _LIBCPP_CONFIG

libcxx/src/locale.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,7 +1114,21 @@ ctype_byname<wchar_t>::~ctype_byname()
11141114
bool
11151115
ctype_byname<wchar_t>::do_is(mask m, char_type c) const
11161116
{
1117+
#ifdef _LIBCPP_WCTYPE_IS_MASK
11171118
return static_cast<bool>(iswctype_l(c, m, __l));
1119+
#else
1120+
if (m & space && !iswspace_l(c, __l)) return false;
1121+
if (m & print && !iswprint_l(c, __l)) return false;
1122+
if (m & cntrl && !iswcntrl_l(c, __l)) return false;
1123+
if (m & upper && !iswupper_l(c, __l)) return false;
1124+
if (m & lower && !iswlower_l(c, __l)) return false;
1125+
if (m & alpha && !iswalpha_l(c, __l)) return false;
1126+
if (m & digit && !iswdigit_l(c, __l)) return false;
1127+
if (m & punct && !iswpunct_l(c, __l)) return false;
1128+
if (m & xdigit && !iswxdigit_l(c, __l)) return false;
1129+
if (m & blank && !iswblank_l(c, __l)) return false;
1130+
return true;
1131+
#endif
11181132
}
11191133

11201134
const wchar_t*
@@ -1154,17 +1168,49 @@ const wchar_t*
11541168
ctype_byname<wchar_t>::do_scan_is(mask m, const char_type* low, const char_type* high) const
11551169
{
11561170
for (; low != high; ++low)
1171+
{
1172+
#ifdef _LIBCPP_WCTYPE_IS_MASK
11571173
if (iswctype_l(*low, m, __l))
11581174
break;
1175+
#else
1176+
if (m & space && !iswspace_l(*low, __l)) continue;
1177+
if (m & print && !iswprint_l(*low, __l)) continue;
1178+
if (m & cntrl && !iswcntrl_l(*low, __l)) continue;
1179+
if (m & upper && !iswupper_l(*low, __l)) continue;
1180+
if (m & lower && !iswlower_l(*low, __l)) continue;
1181+
if (m & alpha && !iswalpha_l(*low, __l)) continue;
1182+
if (m & digit && !iswdigit_l(*low, __l)) continue;
1183+
if (m & punct && !iswpunct_l(*low, __l)) continue;
1184+
if (m & xdigit && !iswxdigit_l(*low, __l)) continue;
1185+
if (m & blank && !iswblank_l(*low, __l)) continue;
1186+
break;
1187+
#endif
1188+
}
11591189
return low;
11601190
}
11611191

11621192
const wchar_t*
11631193
ctype_byname<wchar_t>::do_scan_not(mask m, const char_type* low, const char_type* high) const
11641194
{
11651195
for (; low != high; ++low)
1196+
{
1197+
#ifdef _LIBCPP_WCTYPE_IS_MASK
11661198
if (!iswctype_l(*low, m, __l))
11671199
break;
1200+
#else
1201+
if (m & space && iswspace_l(*low, __l)) continue;
1202+
if (m & print && iswprint_l(*low, __l)) continue;
1203+
if (m & cntrl && iswcntrl_l(*low, __l)) continue;
1204+
if (m & upper && iswupper_l(*low, __l)) continue;
1205+
if (m & lower && iswlower_l(*low, __l)) continue;
1206+
if (m & alpha && iswalpha_l(*low, __l)) continue;
1207+
if (m & digit && iswdigit_l(*low, __l)) continue;
1208+
if (m & punct && iswpunct_l(*low, __l)) continue;
1209+
if (m & xdigit && iswxdigit_l(*low, __l)) continue;
1210+
if (m & blank && iswblank_l(*low, __l)) continue;
1211+
break;
1212+
#endif
1213+
}
11681214
return low;
11691215
}
11701216

0 commit comments

Comments
 (0)