[libcxx-commits] [libcxx] [libc++] Add __iswctype to the locale base API since it's required by <locale> (PR #122168)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Jan 8 14:25:17 PST 2025
https://github.com/ldionne updated https://github.com/llvm/llvm-project/pull/122168
>From 7abe9b3666e82f626bc032dfc1327bb49a2442d6 Mon Sep 17 00:00:00 2001
From: Louis Dionne <ldionne.2 at gmail.com>
Date: Wed, 8 Jan 2025 15:46:43 -0500
Subject: [PATCH] [libc++] Add __iswctype to the locale base API since it's
required by <locale>
---
libcxx/include/__locale_dir/locale_base_api.h | 4 ++++
libcxx/include/__locale_dir/support/bsd_like.h | 4 ++++
libcxx/include/__locale_dir/support/windows.h | 3 +++
libcxx/src/locale.cpp | 10 +++++-----
4 files changed, 16 insertions(+), 5 deletions(-)
diff --git a/libcxx/include/__locale_dir/locale_base_api.h b/libcxx/include/__locale_dir/locale_base_api.h
index 9957429c1e7c23..cda6033b03db78 100644
--- a/libcxx/include/__locale_dir/locale_base_api.h
+++ b/libcxx/include/__locale_dir/locale_base_api.h
@@ -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);
@@ -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); }
diff --git a/libcxx/include/__locale_dir/support/bsd_like.h b/libcxx/include/__locale_dir/support/bsd_like.h
index da31aeaf3c58e3..b3933c71c6b26d 100644
--- a/libcxx/include/__locale_dir/support/bsd_like.h
+++ b/libcxx/include/__locale_dir/support/bsd_like.h
@@ -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); }
diff --git a/libcxx/include/__locale_dir/support/windows.h b/libcxx/include/__locale_dir/support/windows.h
index 03d05a410fdc3b..eca0e17d94c85a 100644
--- a/libcxx/include/__locale_dir/support/windows.h
+++ b/libcxx/include/__locale_dir/support/windows.h
@@ -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); }
diff --git a/libcxx/src/locale.cpp b/libcxx/src/locale.cpp
index a1e10401f0b299..599c61ca7a36da 100644
--- a/libcxx/src/locale.cpp
+++ b/libcxx/src/locale.cpp
@@ -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)
@@ -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);
@@ -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_))
More information about the libcxx-commits
mailing list