From 38c2e4c120c34af9dd5341f481be5ee29f2fb6e0 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sat, 15 Feb 2025 21:56:15 +0100 Subject: [PATCH] isxdigit_l: New module. * lib/ctype.in.h: (isxdigit_l): New declaration. * lib/isxdigit_l.c: New file. * m4/isxdigit_l.m4: New file. * m4/ctype_h.m4 (gl_CTYPE_H): Test for isxdigit_l. (gl_CTYPE_H_REQUIRE_DEFAULTS): Initialize GNULIB_ISXDIGIT_L. (gl_CTYPE_H_DEFAULTS): Initialize HAVE_ISXDIGIT_L. * modules/ctype-h (Makefile.am): Substitute GNULIB_ISXDIGIT_L, HAVE_ISXDIGIT_L. * modules/isxdigit_l: New file. * tests/test-ctype-h-c++.cc: Check declaration of isxdigit_l. * doc/posix-functions/isxdigit_l.texi: Mention the new module. --- ChangeLog | 15 ++++++++++++ doc/posix-functions/isxdigit_l.texi | 9 +++---- lib/ctype.in.h | 20 +++++++++++++++- lib/isxdigit_l.c | 37 +++++++++++++++++++++++++++++ m4/ctype_h.m4 | 6 +++-- m4/isxdigit_l.m4 | 20 ++++++++++++++++ modules/ctype-h | 2 ++ modules/isxdigit_l | 31 ++++++++++++++++++++++++ tests/test-ctype-h-c++.cc | 4 ++++ 9 files changed, 137 insertions(+), 7 deletions(-) create mode 100644 lib/isxdigit_l.c create mode 100644 m4/isxdigit_l.m4 create mode 100644 modules/isxdigit_l diff --git a/ChangeLog b/ChangeLog index e4aa0ddd16..bf7677b9b8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2025-02-15 Bruno Haible + + isxdigit_l: New module. + * lib/ctype.in.h: (isxdigit_l): New declaration. + * lib/isxdigit_l.c: New file. + * m4/isxdigit_l.m4: New file. + * m4/ctype_h.m4 (gl_CTYPE_H): Test for isxdigit_l. + (gl_CTYPE_H_REQUIRE_DEFAULTS): Initialize GNULIB_ISXDIGIT_L. + (gl_CTYPE_H_DEFAULTS): Initialize HAVE_ISXDIGIT_L. + * modules/ctype-h (Makefile.am): Substitute GNULIB_ISXDIGIT_L, + HAVE_ISXDIGIT_L. + * modules/isxdigit_l: New file. + * tests/test-ctype-h-c++.cc: Check declaration of isxdigit_l. + * doc/posix-functions/isxdigit_l.texi: Mention the new module. + 2025-02-15 Bruno Haible isupper_l: Add tests. diff --git a/doc/posix-functions/isxdigit_l.texi b/doc/posix-functions/isxdigit_l.texi index e641922bb9..5c1be9c861 100644 --- a/doc/posix-functions/isxdigit_l.texi +++ b/doc/posix-functions/isxdigit_l.texi @@ -4,15 +4,16 @@ POSIX specification:@* @url{https://pubs.opengroup.org/onlinepubs/9799919799/functions/isxdigit_l.html} -Gnulib module: --- +Gnulib module: isxdigit_l +@mindex isxdigit_l Portability problems fixed by Gnulib: @itemize +@item +This function is missing on many platforms: +FreeBSD 9.0, NetBSD 6.1, OpenBSD 6.1, Minix 3.1.8, AIX 6.1, HP-UX 11, Solaris 11.3, Cygwin 2.5.x, mingw, MSVC 14, Android 4.4. @end itemize Portability problems not fixed by Gnulib: @itemize -@item -This function is missing on many platforms: -FreeBSD 6.0, NetBSD 5.0, OpenBSD 6.0, Minix 3.1.8, AIX 5.1, HP-UX 11, Solaris 11.3, Cygwin 1.7.x, mingw, MSVC 14, Android 4.4. @end itemize diff --git a/lib/ctype.in.h b/lib/ctype.in.h index 6ede5b8841..0aa5175397 100644 --- a/lib/ctype.in.h +++ b/lib/ctype.in.h @@ -57,7 +57,7 @@ #if (@GNULIB_ISALNUM_L@ || @GNULIB_ISALPHA_L@ || @GNULIB_ISBLANK_L@ \ || @GNULIB_ISCNTRL_L@ || @GNULIB_ISDIGIT_L@ || @GNULIB_ISGRAPH_L@ \ || @GNULIB_ISLOWER_L@ || @GNULIB_ISPRINT_L@ || @GNULIB_ISPUNCT_L@ \ - || @GNULIB_ISSPACE_L@ || @GNULIB_ISUPPER_L@) + || @GNULIB_ISSPACE_L@ || @GNULIB_ISUPPER_L@ || @GNULIB_ISXDIGIT_L@) /* Get locale_t. */ # include #endif @@ -277,6 +277,24 @@ _GL_WARN_ON_USE (isupper_l, "isupper_l is unportable - " # endif #endif +/* Return non-zero if c is a hexadecimal digit. */ +#if @GNULIB_ISXDIGIT_L@ +# if !@HAVE_ISXDIGIT_L@ +_GL_FUNCDECL_SYS (isxdigit_l, int, (int c, locale_t locale), + _GL_ARG_NONNULL ((2))); +# endif +_GL_CXXALIAS_SYS (isxdigit_l, int, (int c, locale_t locale)); +# if __GLIBC__ >= 2 +_GL_CXXALIASWARN (isxdigit_l); +# endif +#elif defined GNULIB_POSIXCHECK +# undef isxdigit_l +# if HAVE_RAW_DECL_ISXDIGIT_L +_GL_WARN_ON_USE (isxdigit_l, "isxdigit_l is unportable - " + "use gnulib module isxdigit_l for portability"); +# endif +#endif + #endif /* _@GUARD_PREFIX@_CTYPE_H */ #endif #endif /* _@GUARD_PREFIX@_CTYPE_H */ diff --git a/lib/isxdigit_l.c b/lib/isxdigit_l.c new file mode 100644 index 0000000000..dcc885871d --- /dev/null +++ b/lib/isxdigit_l.c @@ -0,0 +1,37 @@ +/* Test whether a single-byte character is a hexadecimal digit. + Copyright (C) 2025 Free Software Foundation, Inc. + + This file is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 2.1 of the + License, or (at your option) any later version. + + This file is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program. If not, see . */ + +/* Written by Bruno Haible , 2025. */ + +#include + +/* Specification. */ +#include + +int +isxdigit_l (int c, _GL_UNUSED locale_t locale) +{ + /* For consistency with isxdigit(), which is not locale dependent + (see ISO C23 § 7.4.2.12). */ + return ((c >= '0' && c <= '9') +#if 'A' == 0x41 && 'a' == 0x61 + /* Optimization, assuming ASCII */ + || ((c & ~0x20) >= 'A' && (c & ~0x20) <= 'F') +#else + || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f') +#endif + ); +} diff --git a/m4/ctype_h.m4 b/m4/ctype_h.m4 index c2d042f80e..972144c93c 100644 --- a/m4/ctype_h.m4 +++ b/m4/ctype_h.m4 @@ -1,5 +1,5 @@ # ctype_h.m4 -# serial 20 +# serial 21 dnl Copyright (C) 2009-2025 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -17,7 +17,7 @@ AC_DEFUN_ONCE([gl_CTYPE_H], dnl corresponding gnulib module is not in use. gl_WARN_ON_USE_PREPARE([[#include ]], [isalnum_l isalpha_l isblank isblank_l iscntrl_l isdigit_l isgraph_l - islower_l isprint_l ispunct_l isspace_l isupper_l]) + islower_l isprint_l ispunct_l isspace_l isupper_l isxdigit_l]) ]) # gl_CTYPE_MODULE_INDICATOR([modulename]) @@ -49,6 +49,7 @@ AC_DEFUN([gl_CTYPE_H_REQUIRE_DEFAULTS], gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ISPUNCT_L]) gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ISSPACE_L]) gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ISUPPER_L]) + gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ISXDIGIT_L]) ]) m4_require(GL_MODULE_INDICATOR_PREFIX[_CTYPE_H_MODULE_INDICATOR_DEFAULTS]) AC_REQUIRE([gl_CTYPE_H_DEFAULTS]) @@ -69,4 +70,5 @@ AC_DEFUN([gl_CTYPE_H_DEFAULTS], HAVE_ISPUNCT_L=1; AC_SUBST([HAVE_ISPUNCT_L]) HAVE_ISSPACE_L=1; AC_SUBST([HAVE_ISSPACE_L]) HAVE_ISUPPER_L=1; AC_SUBST([HAVE_ISUPPER_L]) + HAVE_ISXDIGIT_L=1; AC_SUBST([HAVE_ISXDIGIT_L]) ]) diff --git a/m4/isxdigit_l.m4 b/m4/isxdigit_l.m4 new file mode 100644 index 0000000000..4ff47c8ee4 --- /dev/null +++ b/m4/isxdigit_l.m4 @@ -0,0 +1,20 @@ +# isxdigit_l.m4 +# serial 1 +dnl Copyright (C) 2009-2025 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. +dnl This file is offered as-is, without any warranty. + +AC_DEFUN([gl_FUNC_ISXDIGIT_L], +[ + AC_REQUIRE([gl_CTYPE_H_DEFAULTS]) + + dnl Persuade glibc to declare isxdigit_l(). + AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) + + AC_CHECK_FUNCS_ONCE([isxdigit_l]) + if test $ac_cv_func_isxdigit_l = no; then + HAVE_ISXDIGIT_L=0 + fi +]) diff --git a/modules/ctype-h b/modules/ctype-h index b46ca2e3f9..b5f428bb44 100644 --- a/modules/ctype-h +++ b/modules/ctype-h @@ -42,6 +42,7 @@ ctype.h: ctype.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(WARN_ON_USE_H) -e 's/@''GNULIB_ISPUNCT_L''@/$(GNULIB_ISPUNCT_L)/g' \ -e 's/@''GNULIB_ISSPACE_L''@/$(GNULIB_ISSPACE_L)/g' \ -e 's/@''GNULIB_ISUPPER_L''@/$(GNULIB_ISUPPER_L)/g' \ + -e 's/@''GNULIB_ISXDIGIT_L''@/$(GNULIB_ISXDIGIT_L)/g' \ -e 's/@''HAVE_ISALNUM_L''@/$(HAVE_ISALNUM_L)/g' \ -e 's/@''HAVE_ISALPHA_L''@/$(HAVE_ISALPHA_L)/g' \ -e 's/@''HAVE_ISBLANK''@/$(HAVE_ISBLANK)/g' \ @@ -54,6 +55,7 @@ ctype.h: ctype.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(WARN_ON_USE_H) -e 's/@''HAVE_ISPUNCT_L''@/$(HAVE_ISPUNCT_L)/g' \ -e 's/@''HAVE_ISSPACE_L''@/$(HAVE_ISSPACE_L)/g' \ -e 's/@''HAVE_ISUPPER_L''@/$(HAVE_ISUPPER_L)/g' \ + -e 's/@''HAVE_ISXDIGIT_L''@/$(HAVE_ISXDIGIT_L)/g' \ -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \ $(srcdir)/ctype.in.h > $@-t diff --git a/modules/isxdigit_l b/modules/isxdigit_l new file mode 100644 index 0000000000..5ec944dbcd --- /dev/null +++ b/modules/isxdigit_l @@ -0,0 +1,31 @@ +Description: +isxdigit_l() function: test whether a single-byte character is a hexadecimal digit. + +Files: +lib/isxdigit_l.c +m4/isxdigit_l.m4 + +Depends-on: +ctype-h +locale-h +extensions + +configure.ac: +gl_FUNC_ISXDIGIT_L +gl_CONDITIONAL([GL_COND_OBJ_ISXDIGIT_L], [test $HAVE_ISXDIGIT_L = 0]) +gl_MODULE_INDICATOR([isxdigit_l]) +gl_CTYPE_MODULE_INDICATOR([isxdigit_l]) + +Makefile.am: +if GL_COND_OBJ_ISXDIGIT_L +lib_SOURCES += isxdigit_l.c +endif + +Include: + + +License: +LGPLv2+ + +Maintainer: +all diff --git a/tests/test-ctype-h-c++.cc b/tests/test-ctype-h-c++.cc index c10be107ef..cce73591e4 100644 --- a/tests/test-ctype-h-c++.cc +++ b/tests/test-ctype-h-c++.cc @@ -72,6 +72,10 @@ SIGNATURE_CHECK (GNULIB_NAMESPACE::isspace_l, int, (int, locale_t)); SIGNATURE_CHECK (GNULIB_NAMESPACE::isupper_l, int, (int, locale_t)); #endif +#if GNULIB_TEST_ISXDIGIT_L +SIGNATURE_CHECK (GNULIB_NAMESPACE::isxdigit_l, int, (int, locale_t)); +#endif + int main () -- 2.39.5