From 4204b429c1d0abc60f634accff953c2d3264c47a Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sat, 15 Feb 2025 19:25:49 +0100 Subject: [PATCH] isdigit_l: New module. * lib/ctype.in.h: (isdigit_l): New declaration. * lib/isdigit_l.c: New file. * m4/isdigit_l.m4: New file. * m4/ctype_h.m4 (gl_CTYPE_H): Test for isdigit_l. (gl_CTYPE_H_REQUIRE_DEFAULTS): Initialize GNULIB_ISDIGIT_L. (gl_CTYPE_H_DEFAULTS): Initialize HAVE_ISDIGIT_L. * modules/ctype-h (Makefile.am): Substitute GNULIB_ISDIGIT_L, HAVE_ISDIGIT_L. * modules/isdigit_l: New file. * tests/test-ctype-h-c++.cc: Check declaration of isdigit_l. * doc/posix-functions/isdigit_l.texi: Mention the new module. --- ChangeLog | 15 +++++++++++++++ doc/posix-functions/isdigit_l.texi | 9 +++++---- lib/ctype.in.h | 20 ++++++++++++++++++- lib/isdigit_l.c | 30 +++++++++++++++++++++++++++++ m4/ctype_h.m4 | 6 ++++-- m4/isdigit_l.m4 | 20 +++++++++++++++++++ modules/ctype-h | 2 ++ modules/isdigit_l | 31 ++++++++++++++++++++++++++++++ tests/test-ctype-h-c++.cc | 4 ++++ 9 files changed, 130 insertions(+), 7 deletions(-) create mode 100644 lib/isdigit_l.c create mode 100644 m4/isdigit_l.m4 create mode 100644 modules/isdigit_l diff --git a/ChangeLog b/ChangeLog index 76dbcf7f73..dd4e2a1c07 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2025-02-15 Bruno Haible + + isdigit_l: New module. + * lib/ctype.in.h: (isdigit_l): New declaration. + * lib/isdigit_l.c: New file. + * m4/isdigit_l.m4: New file. + * m4/ctype_h.m4 (gl_CTYPE_H): Test for isdigit_l. + (gl_CTYPE_H_REQUIRE_DEFAULTS): Initialize GNULIB_ISDIGIT_L. + (gl_CTYPE_H_DEFAULTS): Initialize HAVE_ISDIGIT_L. + * modules/ctype-h (Makefile.am): Substitute GNULIB_ISDIGIT_L, + HAVE_ISDIGIT_L. + * modules/isdigit_l: New file. + * tests/test-ctype-h-c++.cc: Check declaration of isdigit_l. + * doc/posix-functions/isdigit_l.texi: Mention the new module. + 2025-02-15 Bruno Haible iscntrl_l: Add tests. diff --git a/doc/posix-functions/isdigit_l.texi b/doc/posix-functions/isdigit_l.texi index d3a4a26a1c..1429493faf 100644 --- a/doc/posix-functions/isdigit_l.texi +++ b/doc/posix-functions/isdigit_l.texi @@ -4,15 +4,16 @@ POSIX specification:@* @url{https://pubs.opengroup.org/onlinepubs/9799919799/functions/isdigit_l.html} -Gnulib module: --- +Gnulib module: isdigit_l +@mindex isdigit_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 3e14d35a08..7495eae47f 100644 --- a/lib/ctype.in.h +++ b/lib/ctype.in.h @@ -55,7 +55,7 @@ #endif #if (@GNULIB_ISALNUM_L@ || @GNULIB_ISALPHA_L@ || @GNULIB_ISBLANK_L@ \ - || @GNULIB_ISCNTRL_L@) + || @GNULIB_ISCNTRL_L@ || @GNULIB_ISDIGIT_L@) /* Get locale_t. */ # include #endif @@ -149,6 +149,24 @@ _GL_WARN_ON_USE (iscntrl_l, "iscntrl_l is unportable - " # endif #endif +/* Return non-zero if c is a digit. */ +#if @GNULIB_ISDIGIT_L@ +# if !@HAVE_ISDIGIT_L@ +_GL_FUNCDECL_SYS (isdigit_l, int, (int c, locale_t locale), + _GL_ARG_NONNULL ((2))); +# endif +_GL_CXXALIAS_SYS (isdigit_l, int, (int c, locale_t locale)); +# if __GLIBC__ >= 2 +_GL_CXXALIASWARN (isdigit_l); +# endif +#elif defined GNULIB_POSIXCHECK +# undef isdigit_l +# if HAVE_RAW_DECL_ISDIGIT_L +_GL_WARN_ON_USE (isdigit_l, "isdigit_l is unportable - " + "use gnulib module isdigit_l for portability"); +# endif +#endif + #endif /* _@GUARD_PREFIX@_CTYPE_H */ #endif #endif /* _@GUARD_PREFIX@_CTYPE_H */ diff --git a/lib/isdigit_l.c b/lib/isdigit_l.c new file mode 100644 index 0000000000..9a085582fe --- /dev/null +++ b/lib/isdigit_l.c @@ -0,0 +1,30 @@ +/* Test whether a single-byte character is a 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 +isdigit_l (int c, _GL_UNUSED locale_t locale) +{ + /* For consistency with isdigit(), which is not locale dependent + (see ISO C23 § 7.4.2.5). */ + return c >= '0' && c <= '9'; +} diff --git a/m4/ctype_h.m4 b/m4/ctype_h.m4 index 10053e3e43..b8c937e09d 100644 --- a/m4/ctype_h.m4 +++ b/m4/ctype_h.m4 @@ -1,5 +1,5 @@ # ctype_h.m4 -# serial 13 +# serial 14 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, @@ -16,7 +16,7 @@ AC_DEFUN_ONCE([gl_CTYPE_H], dnl Check for declarations of anything we want to poison if the dnl corresponding gnulib module is not in use. gl_WARN_ON_USE_PREPARE([[#include - ]], [isalnum_l isalpha_l isblank isblank_l iscntrl_l]) + ]], [isalnum_l isalpha_l isblank isblank_l iscntrl_l isdigit_l]) ]) # gl_CTYPE_MODULE_INDICATOR([modulename]) @@ -41,6 +41,7 @@ AC_DEFUN([gl_CTYPE_H_REQUIRE_DEFAULTS], gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ISBLANK]) gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ISBLANK_L]) gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ISCNTRL_L]) + gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ISDIGIT_L]) ]) m4_require(GL_MODULE_INDICATOR_PREFIX[_CTYPE_H_MODULE_INDICATOR_DEFAULTS]) AC_REQUIRE([gl_CTYPE_H_DEFAULTS]) @@ -54,4 +55,5 @@ AC_DEFUN([gl_CTYPE_H_DEFAULTS], HAVE_ISBLANK=1; AC_SUBST([HAVE_ISBLANK]) HAVE_ISBLANK_L=1; AC_SUBST([HAVE_ISBLANK_L]) HAVE_ISCNTRL_L=1; AC_SUBST([HAVE_ISCNTRL_L]) + HAVE_ISDIGIT_L=1; AC_SUBST([HAVE_ISDIGIT_L]) ]) diff --git a/m4/isdigit_l.m4 b/m4/isdigit_l.m4 new file mode 100644 index 0000000000..8ebaa47998 --- /dev/null +++ b/m4/isdigit_l.m4 @@ -0,0 +1,20 @@ +# isdigit_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_ISDIGIT_L], +[ + AC_REQUIRE([gl_CTYPE_H_DEFAULTS]) + + dnl Persuade glibc to declare isdigit_l(). + AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) + + AC_CHECK_FUNCS_ONCE([isdigit_l]) + if test $ac_cv_func_isdigit_l = no; then + HAVE_ISDIGIT_L=0 + fi +]) diff --git a/modules/ctype-h b/modules/ctype-h index 7334f37776..a9a631dedc 100644 --- a/modules/ctype-h +++ b/modules/ctype-h @@ -35,11 +35,13 @@ ctype.h: ctype.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(WARN_ON_USE_H) -e 's/@''GNULIB_ISBLANK''@/$(GNULIB_ISBLANK)/g' \ -e 's/@''GNULIB_ISBLANK_L''@/$(GNULIB_ISBLANK_L)/g' \ -e 's/@''GNULIB_ISCNTRL_L''@/$(GNULIB_ISCNTRL_L)/g' \ + -e 's/@''GNULIB_ISDIGIT_L''@/$(GNULIB_ISDIGIT_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' \ -e 's/@''HAVE_ISBLANK_L''@/$(HAVE_ISBLANK_L)/g' \ -e 's/@''HAVE_ISCNTRL_L''@/$(HAVE_ISCNTRL_L)/g' \ + -e 's/@''HAVE_ISDIGIT_L''@/$(HAVE_ISDIGIT_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/isdigit_l b/modules/isdigit_l new file mode 100644 index 0000000000..1a66986423 --- /dev/null +++ b/modules/isdigit_l @@ -0,0 +1,31 @@ +Description: +isdigit_l() function: test whether a single-byte character is a digit. + +Files: +lib/isdigit_l.c +m4/isdigit_l.m4 + +Depends-on: +ctype-h +locale-h +extensions + +configure.ac: +gl_FUNC_ISDIGIT_L +gl_CONDITIONAL([GL_COND_OBJ_ISDIGIT_L], [test $HAVE_ISDIGIT_L = 0]) +gl_MODULE_INDICATOR([isdigit_l]) +gl_CTYPE_MODULE_INDICATOR([isdigit_l]) + +Makefile.am: +if GL_COND_OBJ_ISDIGIT_L +lib_SOURCES += isdigit_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 7031d4458a..42fd8fc86b 100644 --- a/tests/test-ctype-h-c++.cc +++ b/tests/test-ctype-h-c++.cc @@ -44,6 +44,10 @@ SIGNATURE_CHECK (GNULIB_NAMESPACE::isblank_l, int, (int, locale_t)); SIGNATURE_CHECK (GNULIB_NAMESPACE::iscntrl_l, int, (int, locale_t)); #endif +#if GNULIB_TEST_ISDIGIT_L +SIGNATURE_CHECK (GNULIB_NAMESPACE::isdigit_l, int, (int, locale_t)); +#endif + int main () -- 2.39.5