Skip to content

[libc++] Add __iswctype to the locale base API since it's required by <locale> #122168

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions libcxx/include/__locale_dir/locale_base_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
// int __strcoll(const char*, const char*, __locale_t);
// size_t __strxfrm(char*, const char*, size_t, __locale_t);
//
// int __iswctype(wint_t, wctype_t, __locale_t);
// int __iswspace(wint_t, __locale_t);
// int __iswprint(wint_t, __locale_t);
// int __iswcntrl(wint_t, __locale_t);
Expand Down Expand Up @@ -192,6 +193,9 @@ inline _LIBCPP_HIDE_FROM_ABI int __wcscoll(const wchar_t* __s1, const wchar_t* _
inline _LIBCPP_HIDE_FROM_ABI size_t __wcsxfrm(wchar_t* __dest, const wchar_t* __src, size_t __n, __locale_t __loc) {
return wcsxfrm_l(__dest, __src, __n, __loc);
}
inline _LIBCPP_HIDE_FROM_ABI int __iswctype(wint_t __ch, wctype_t __type, __locale_t __loc) {
return iswctype_l(__ch, __type, __loc);
}
inline _LIBCPP_HIDE_FROM_ABI int __iswspace(wint_t __ch, __locale_t __loc) { return iswspace_l(__ch, __loc); }
inline _LIBCPP_HIDE_FROM_ABI int __iswprint(wint_t __ch, __locale_t __loc) { return iswprint_l(__ch, __loc); }
inline _LIBCPP_HIDE_FROM_ABI int __iswcntrl(wint_t __ch, __locale_t __loc) { return iswcntrl_l(__ch, __loc); }
Expand Down
4 changes: 4 additions & 0 deletions libcxx/include/__locale_dir/support/bsd_like.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ inline _LIBCPP_HIDE_FROM_ABI size_t __strxfrm(char* __dest, const char* __src, s
}

#if _LIBCPP_HAS_WIDE_CHARACTERS
inline _LIBCPP_HIDE_FROM_ABI int __iswctype(wint_t __c, wctype_t __type, __locale_t __loc) {
return ::iswctype_l(__c, __type, __loc);
}

inline _LIBCPP_HIDE_FROM_ABI int __iswspace(wint_t __c, __locale_t __loc) { return ::iswspace_l(__c, __loc); }

inline _LIBCPP_HIDE_FROM_ABI int __iswprint(wint_t __c, __locale_t __loc) { return ::iswprint_l(__c, __loc); }
Expand Down
3 changes: 3 additions & 0 deletions libcxx/include/__locale_dir/support/windows.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ inline _LIBCPP_HIDE_FROM_ABI size_t __strxfrm(char* __dest, const char* __src, s
}

#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
inline _LIBCPP_HIDE_FROM_ABI int __iswctype(wint_t __c, wctype_t __type, __locale_t __loc) {
return ::_iswctype_l(__c, __type, __loc);
}
inline _LIBCPP_HIDE_FROM_ABI int __iswspace(wint_t __c, __locale_t __loc) { return ::_iswspace_l(__c, __loc); }
inline _LIBCPP_HIDE_FROM_ABI int __iswprint(wint_t __c, __locale_t __loc) { return ::_iswprint_l(__c, __loc); }
inline _LIBCPP_HIDE_FROM_ABI int __iswcntrl(wint_t __c, __locale_t __loc) { return ::_iswcntrl_l(__c, __loc); }
Expand Down
10 changes: 5 additions & 5 deletions libcxx/src/locale.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1109,11 +1109,11 @@ ctype_byname<wchar_t>::ctype_byname(const string& name, size_t refs)
ctype_byname<wchar_t>::~ctype_byname() { __locale::__freelocale(__l_); }

bool ctype_byname<wchar_t>::do_is(mask m, char_type c) const {
wint_t ch = static_cast<wint_t>(c);
# ifdef _LIBCPP_WCTYPE_IS_MASK
return static_cast<bool>(iswctype_l(c, m, __l_));
return static_cast<bool>(__locale::__iswctype(ch, m, __l_));
# else
bool result = false;
wint_t ch = static_cast<wint_t>(c);
if ((m & space) == space)
result |= (__locale::__iswspace(ch, __l_) != 0);
if ((m & print) == print)
Expand Down Expand Up @@ -1179,7 +1179,7 @@ const wchar_t* ctype_byname<wchar_t>::do_is(const char_type* low, const char_typ
const wchar_t* ctype_byname<wchar_t>::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_))
if (__locale::__iswctype(static_cast<wint_t>(*low), m, __l_))
break;
# else
wint_t ch = static_cast<wint_t>(*low);
Expand Down Expand Up @@ -1210,11 +1210,11 @@ const wchar_t* ctype_byname<wchar_t>::do_scan_is(mask m, const char_type* low, c

const wchar_t* ctype_byname<wchar_t>::do_scan_not(mask m, const char_type* low, const char_type* high) const {
for (; low != high; ++low) {
wint_t ch = static_cast<wint_t>(*low);
# ifdef _LIBCPP_WCTYPE_IS_MASK
if (!iswctype_l(*low, m, __l_))
if (!__locale::__iswctype(ch, m, __l_))
break;
# else
wint_t ch = static_cast<wint_t>(*low);
if ((m & space) == space && __locale::__iswspace(ch, __l_))
continue;
if ((m & print) == print && __locale::__iswprint(ch, __l_))
Expand Down
Loading