Index: libcxx/include/__locale =================================================================== --- libcxx/include/__locale +++ libcxx/include/__locale @@ -568,6 +568,16 @@ explicit ctype(size_t __refs = 0) : locale::facet(__refs) {} + _LIBCPP_HIDE_FROM_ABI + static bool __is_valid_in_encoding(char_type __c) + { +#if defined(__MVS__) + return (__c >=0 && __c < 256); +#else + return isascii(__c); +#endif + } + _LIBCPP_INLINE_VISIBILITY bool is(mask __m, char_type __c) const { @@ -670,17 +680,28 @@ explicit ctype(const mask* __tab = nullptr, bool __del = false, size_t __refs = 0); + _LIBCPP_HIDE_FROM_ABI + static bool __is_valid_in_encoding(char_type __c) + { +#if defined(__MVS__) + (void)__c; + return true; +#else + return isascii(__c); +#endif + } + _LIBCPP_INLINE_VISIBILITY bool is(mask __m, char_type __c) const { - return isascii(__c) ? (__tab_[static_cast(__c)] & __m) !=0 : false; + return __is_valid_in_encoding(__c) ? (__tab_[static_cast(__c)] & __m) !=0 : false; } _LIBCPP_INLINE_VISIBILITY const char_type* is(const char_type* __low, const char_type* __high, mask* __vec) const { for (; __low != __high; ++__low, ++__vec) - *__vec = isascii(*__low) ? __tab_[static_cast(*__low)] : 0; + *__vec = __is_valid_in_encoding(*__low) ? __tab_[static_cast(*__low)] : 0; return __low; } @@ -688,7 +709,7 @@ const char_type* scan_is (mask __m, const char_type* __low, const char_type* __high) const { for (; __low != __high; ++__low) - if (isascii(*__low) && (__tab_[static_cast(*__low)] & __m)) + if (__is_valid_in_encoding(*__low) && (__tab_[static_cast(*__low)] & __m)) break; return __low; } @@ -697,7 +718,7 @@ const char_type* scan_not(mask __m, const char_type* __low, const char_type* __high) const { for (; __low != __high; ++__low) - if (!(isascii(*__low) && (__tab_[static_cast(*__low)] & __m))) + if (!(__is_valid_in_encoding(*__low) && (__tab_[static_cast(*__low)] & __m))) break; return __low; } Index: libcxx/src/locale.cpp =================================================================== --- libcxx/src/locale.cpp +++ libcxx/src/locale.cpp @@ -862,15 +862,14 @@ bool ctype::do_is(mask m, char_type c) const { - return isascii(c) ? (ctype::classic_table()[c] & m) != 0 : false; + return __is_valid_in_encoding(c) ? (ctype::classic_table()[c] & m) != 0 : false; } const wchar_t* ctype::do_is(const char_type* low, const char_type* high, mask* vec) const { for (; low != high; ++low, ++vec) - *vec = static_cast(isascii(*low) ? - ctype::classic_table()[*low] : 0); + *vec = static_cast(__is_valid_in_encoding(*low) ? ctype::classic_table()[*low] : 0); return low; } @@ -878,8 +877,8 @@ ctype::do_scan_is(mask m, const char_type* low, const char_type* high) const { for (; low != high; ++low) - if (isascii(*low) && (ctype::classic_table()[*low] & m)) - break; + if (__is_valid_in_encoding(*low) && (ctype::classic_table()[*low] & m)) + break; return low; } @@ -887,8 +886,8 @@ ctype::do_scan_not(mask m, const char_type* low, const char_type* high) const { for (; low != high; ++low) - if (!(isascii(*low) && (ctype::classic_table()[*low] & m))) - break; + if (!(__is_valid_in_encoding(*low) && (ctype::classic_table()[*low] & m))) + break; return low; } @@ -896,13 +895,12 @@ ctype::do_toupper(char_type c) const { #ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE - return isascii(c) ? _DefaultRuneLocale.__mapupper[c] : c; -#elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || \ - defined(__NetBSD__) || defined(__MVS__) - return isascii(c) ? ctype::__classic_upper_table()[c] : c; -#else - return (isascii(c) && iswlower_l(c, _LIBCPP_GET_C_LOCALE)) ? c-L'a'+L'A' : c; -#endif + return __is_valid_in_encoding(c) ? _DefaultRuneLocale.__mapupper[c] : c; +# elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || defined(__NetBSD__) || defined(__MVS__) + return __is_valid_in_encoding(c) ? ctype::__classic_upper_table()[c] : c; +# else + return (__is_valid_in_encoding(c) && iswlower_l(c, _LIBCPP_GET_C_LOCALE)) ? c - L'a' + L'A' : c; +# endif } const wchar_t* @@ -910,13 +908,12 @@ { for (; low != high; ++low) #ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE - *low = isascii(*low) ? _DefaultRuneLocale.__mapupper[*low] : *low; + *low = __is_valid_in_encoding(*low) ? _DefaultRuneLocale.__mapupper[*low] : *low; #elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || \ defined(__NetBSD__) || defined(__MVS__) - *low = isascii(*low) ? ctype::__classic_upper_table()[*low] - : *low; + *low = __is_valid_in_encoding(*low) ? ctype::__classic_upper_table()[*low] : *low; #else - *low = (isascii(*low) && islower_l(*low, _LIBCPP_GET_C_LOCALE)) ? (*low-L'a'+L'A') : *low; + *low = (__is_valid_in_encoding(*low) && islower_l(*low, _LIBCPP_GET_C_LOCALE)) ? (*low - L'a' + L'A') : *low; #endif return low; } @@ -925,13 +922,12 @@ ctype::do_tolower(char_type c) const { #ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE - return isascii(c) ? _DefaultRuneLocale.__maplower[c] : c; -#elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || \ - defined(__NetBSD__) || defined(__MVS__) - return isascii(c) ? ctype::__classic_lower_table()[c] : c; -#else - return (isascii(c) && isupper_l(c, _LIBCPP_GET_C_LOCALE)) ? c-L'A'+'a' : c; -#endif + return __is_valid_in_encoding(c) ? _DefaultRuneLocale.__maplower[c] : c; +# elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || defined(__NetBSD__) || defined(__MVS__) + return __is_valid_in_encoding(c) ? ctype::__classic_lower_table()[c] : c; +# else + return (__is_valid_in_encoding(c) && isupper_l(c, _LIBCPP_GET_C_LOCALE)) ? c - L'A' + 'a' : c; +# endif } const wchar_t* @@ -939,13 +935,12 @@ { for (; low != high; ++low) #ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE - *low = isascii(*low) ? _DefaultRuneLocale.__maplower[*low] : *low; + *low = __is_valid_in_encoding(*low) ? _DefaultRuneLocale.__maplower[*low] : *low; #elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || \ defined(__NetBSD__) || defined(__MVS__) - *low = isascii(*low) ? ctype::__classic_lower_table()[*low] - : *low; + *low = __is_valid_in_encoding(*low) ? ctype::__classic_lower_table()[*low] : *low; #else - *low = (isascii(*low) && isupper_l(*low, _LIBCPP_GET_C_LOCALE)) ? *low-L'A'+L'a' : *low; + *low = (__is_valid_in_encoding(*low) && isupper_l(*low, _LIBCPP_GET_C_LOCALE)) ? *low - L'A' + L'a' : *low; #endif return low; } @@ -967,19 +962,19 @@ char ctype::do_narrow(char_type c, char dfault) const { - if (isascii(c)) - return static_cast(c); - return dfault; + if (__is_valid_in_encoding(c)) + return static_cast(c); + return dfault; } const wchar_t* ctype::do_narrow(const char_type* low, const char_type* high, char dfault, char* dest) const { for (; low != high; ++low, ++dest) - if (isascii(*low)) - *dest = static_cast(*low); - else - *dest = dfault; + if (__is_valid_in_encoding(*low)) + *dest = static_cast(*low); + else + *dest = dfault; return low; } #endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS @@ -1009,15 +1004,13 @@ ctype::do_toupper(char_type c) const { #ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE - return isascii(c) ? - static_cast(_DefaultRuneLocale.__mapupper[static_cast(c)]) : c; + return __is_valid_in_encoding(c) ? static_cast(_DefaultRuneLocale.__mapupper[static_cast(c)]) : c; #elif defined(__NetBSD__) - return static_cast(__classic_upper_table()[static_cast(c)]); + return static_cast(__classic_upper_table()[static_cast(c)]); #elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || defined(__MVS__) - return isascii(c) ? - static_cast(__classic_upper_table()[static_cast(c)]) : c; + return __is_valid_in_encoding(c) ? static_cast(__classic_upper_table()[static_cast(c)]) : c; #else - return (isascii(c) && islower_l(c, _LIBCPP_GET_C_LOCALE)) ? c-'a'+'A' : c; + return (__is_valid_in_encoding(c) && islower_l(c, _LIBCPP_GET_C_LOCALE)) ? c - 'a' + 'A' : c; #endif } @@ -1026,15 +1019,16 @@ { for (; low != high; ++low) #ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE - *low = isascii(*low) ? - static_cast(_DefaultRuneLocale.__mapupper[static_cast(*low)]) : *low; + *low = __is_valid_in_encoding(*low) + ? static_cast(_DefaultRuneLocale.__mapupper[static_cast(*low)]) + : *low; #elif defined(__NetBSD__) - *low = static_cast(__classic_upper_table()[static_cast(*low)]); + *low = static_cast(__classic_upper_table()[static_cast(*low)]); #elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || defined(__MVS__) - *low = isascii(*low) ? - static_cast(__classic_upper_table()[static_cast(*low)]) : *low; + *low = + __is_valid_in_encoding(*low) ? static_cast(__classic_upper_table()[static_cast(*low)]) : *low; #else - *low = (isascii(*low) && islower_l(*low, _LIBCPP_GET_C_LOCALE)) ? *low-'a'+'A' : *low; + *low = (__is_valid_in_encoding(*low) && islower_l(*low, _LIBCPP_GET_C_LOCALE)) ? *low - 'a' + 'A' : *low; #endif return low; } @@ -1043,15 +1037,13 @@ ctype::do_tolower(char_type c) const { #ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE - return isascii(c) ? - static_cast(_DefaultRuneLocale.__maplower[static_cast(c)]) : c; + return __is_valid_in_encoding(c) ? static_cast(_DefaultRuneLocale.__maplower[static_cast(c)]) : c; #elif defined(__NetBSD__) - return static_cast(__classic_lower_table()[static_cast(c)]); + return static_cast(__classic_lower_table()[static_cast(c)]); #elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || defined(__MVS__) - return isascii(c) ? - static_cast(__classic_lower_table()[static_cast(c)]) : c; + return __is_valid_in_encoding(c) ? static_cast(__classic_lower_table()[static_cast(c)]) : c; #else - return (isascii(c) && isupper_l(c, _LIBCPP_GET_C_LOCALE)) ? c-'A'+'a' : c; + return (__is_valid_in_encoding(c) && isupper_l(c, _LIBCPP_GET_C_LOCALE)) ? c - 'A' + 'a' : c; #endif } @@ -1060,13 +1052,16 @@ { for (; low != high; ++low) #ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE - *low = isascii(*low) ? static_cast(_DefaultRuneLocale.__maplower[static_cast(*low)]) : *low; + *low = __is_valid_in_encoding(*low) + ? static_cast(_DefaultRuneLocale.__maplower[static_cast(*low)]) + : *low; #elif defined(__NetBSD__) - *low = static_cast(__classic_lower_table()[static_cast(*low)]); + *low = static_cast(__classic_lower_table()[static_cast(*low)]); #elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || defined(__MVS__) - *low = isascii(*low) ? static_cast(__classic_lower_table()[static_cast(*low)]) : *low; + *low = + __is_valid_in_encoding(*low) ? static_cast(__classic_lower_table()[static_cast(*low)]) : *low; #else - *low = (isascii(*low) && isupper_l(*low, _LIBCPP_GET_C_LOCALE)) ? *low-'A'+'a' : *low; + *low = (__is_valid_in_encoding(*low) && isupper_l(*low, _LIBCPP_GET_C_LOCALE)) ? *low - 'A' + 'a' : *low; #endif return low; } @@ -1088,19 +1083,19 @@ char ctype::do_narrow(char_type c, char dfault) const { - if (isascii(c)) - return static_cast(c); - return dfault; + if (__is_valid_in_encoding(c)) + return static_cast(c); + return dfault; } const char* ctype::do_narrow(const char_type* low, const char_type* high, char dfault, char* dest) const { for (; low != high; ++low, ++dest) - if (isascii(*low)) - *dest = *low; - else - *dest = dfault; + if (__is_valid_in_encoding(*low)) + *dest = *low; + else + *dest = dfault; return low; } @@ -1392,14 +1387,13 @@ { for (; low != high; ++low, ++vec) { - if (isascii(*low)) - *vec = static_cast(ctype::classic_table()[*low]); - else - { - *vec = 0; - wint_t ch = static_cast(*low); - if (iswspace_l(ch, __l)) - *vec |= space; + if (__is_valid_in_encoding(*low)) + *vec = static_cast(ctype::classic_table()[*low]); + else { + *vec = 0; + wint_t ch = static_cast(*low); + if (iswspace_l(ch, __l)) + *vec |= space; #ifndef _LIBCPP_CTYPE_MASK_IS_COMPOSITE_PRINT if (iswprint_l(ch, __l)) *vec |= print;