Skip to content

Commit c85f62f

Browse files
committed
[libc++] Implement our own is{,x}digit functions for the C locale
1 parent 3cf2ac8 commit c85f62f

File tree

6 files changed

+9
-23
lines changed

6 files changed

+9
-23
lines changed

libcxx/include/__locale_dir/locale_base_api.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@
6464
// Character manipulation functions
6565
// --------------------------------
6666
// namespace __locale {
67-
// int __isdigit(int, __locale_t); // required by the headers
68-
// int __isxdigit(int, __locale_t); // required by the headers
6967
// int __toupper(int, __locale_t);
7068
// int __tolower(int, __locale_t);
7169
// int __strcoll(const char*, const char*, __locale_t);
@@ -204,9 +202,6 @@ __strtoull(const char* __nptr, char** __endptr, int __base, __locale_t __loc) {
204202
//
205203
// Character manipulation functions
206204
//
207-
inline _LIBCPP_HIDE_FROM_ABI int __isdigit(int __ch, __locale_t __loc) { return isdigit_l(__ch, __loc); }
208-
inline _LIBCPP_HIDE_FROM_ABI int __isxdigit(int __ch, __locale_t __loc) { return isxdigit_l(__ch, __loc); }
209-
210205
# if defined(_LIBCPP_BUILDING_LIBRARY)
211206
inline _LIBCPP_HIDE_FROM_ABI int __strcoll(const char* __s1, const char* __s2, __locale_t __loc) {
212207
return strcoll_l(__s1, __s2, __loc);

libcxx/include/__locale_dir/num.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,13 @@ void __num_put<_CharT>::__widen_and_group_int(
748748
__op = __ob + (__np - __nb);
749749
}
750750

751+
_LIBCPP_HIDE_FROM_ABI inline bool __isdigit(char __c) { return __c >= '0' && __c <= '9'; }
752+
753+
_LIBCPP_HIDE_FROM_ABI inline bool __isxdigit(char __c) {
754+
auto __lower = __c | 0x20;
755+
return std::__isdigit(__c) || (__lower >= 'a' && __lower <= 'f');
756+
}
757+
751758
template <class _CharT>
752759
void __num_put<_CharT>::__widen_and_group_float(
753760
char* __nb, char* __np, char* __ne, _CharT* __ob, _CharT*& __op, _CharT*& __oe, const locale& __loc) {
@@ -763,11 +770,11 @@ void __num_put<_CharT>::__widen_and_group_float(
763770
*__oe++ = __ct.widen(*__nf++);
764771
*__oe++ = __ct.widen(*__nf++);
765772
for (__ns = __nf; __ns < __ne; ++__ns)
766-
if (!__locale::__isxdigit(*__ns, _LIBCPP_GET_C_LOCALE))
773+
if (!std::__isxdigit(*__ns))
767774
break;
768775
} else {
769776
for (__ns = __nf; __ns < __ne; ++__ns)
770-
if (!__locale::__isdigit(*__ns, _LIBCPP_GET_C_LOCALE))
777+
if (!std::__isdigit(*__ns))
771778
break;
772779
}
773780
if (__grouping.empty()) {

libcxx/include/__locale_dir/support/bsd_like.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,6 @@ __strtoull(const char* __nptr, char** __endptr, int __base, __locale_t __loc) {
8989
//
9090
// Character manipulation functions
9191
//
92-
inline _LIBCPP_HIDE_FROM_ABI int __isdigit(int __c, __locale_t __loc) { return ::isdigit_l(__c, __loc); }
93-
94-
inline _LIBCPP_HIDE_FROM_ABI int __isxdigit(int __c, __locale_t __loc) { return ::isxdigit_l(__c, __loc); }
95-
9692
#if defined(_LIBCPP_BUILDING_LIBRARY)
9793
inline _LIBCPP_HIDE_FROM_ABI int __toupper(int __c, __locale_t __loc) { return ::toupper_l(__c, __loc); }
9894

libcxx/include/__locale_dir/support/linux.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,6 @@ __strtoull(const char* __nptr, char** __endptr, int __base, __locale_t __loc) {
116116
//
117117
// Character manipulation functions
118118
//
119-
inline _LIBCPP_HIDE_FROM_ABI int __isdigit(int __c, __locale_t __loc) { return isdigit_l(__c, __loc); }
120-
121-
inline _LIBCPP_HIDE_FROM_ABI int __isxdigit(int __c, __locale_t __loc) { return isxdigit_l(__c, __loc); }
122-
123119
#if defined(_LIBCPP_BUILDING_LIBRARY)
124120
inline _LIBCPP_HIDE_FROM_ABI int __toupper(int __c, __locale_t __loc) { return toupper_l(__c, __loc); }
125121

libcxx/include/__locale_dir/support/no_locale/characters.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ namespace __locale {
2929
//
3030
// Character manipulation functions
3131
//
32-
inline _LIBCPP_HIDE_FROM_ABI int __isdigit(int __c, __locale_t) { return std::isdigit(__c); }
33-
34-
inline _LIBCPP_HIDE_FROM_ABI int __isxdigit(int __c, __locale_t) { return std::isxdigit(__c); }
35-
3632
#if defined(_LIBCPP_BUILDING_LIBRARY)
3733
inline _LIBCPP_HIDE_FROM_ABI int __toupper(int __c, __locale_t) { return std::toupper(__c); }
3834

libcxx/include/__locale_dir/support/windows.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,6 @@ __strtoull(const char* __nptr, char** __endptr, int __base, __locale_t __loc) {
197197
//
198198
// Character manipulation functions
199199
//
200-
inline _LIBCPP_HIDE_FROM_ABI int __isdigit(int __c, __locale_t __loc) { return _isdigit_l(__c, __loc); }
201-
202-
inline _LIBCPP_HIDE_FROM_ABI int __isxdigit(int __c, __locale_t __loc) { return _isxdigit_l(__c, __loc); }
203-
204200
#if defined(_LIBCPP_BUILDING_LIBRARY)
205201
inline _LIBCPP_HIDE_FROM_ABI int __toupper(int __c, __locale_t __loc) { return ::_toupper_l(__c, __loc); }
206202

0 commit comments

Comments
 (0)