]> Savannah Git Hosting - gnulib.git/commitdiff
isalnum_l: New module.
authorBruno Haible <bruno@clisp.org>
Fri, 14 Feb 2025 05:17:24 +0000 (06:17 +0100)
committerBruno Haible <bruno@clisp.org>
Fri, 14 Feb 2025 14:43:40 +0000 (15:43 +0100)
* lib/ctype.in.h: Include <locale.h>.
(isalnum_l): New declaration.
* lib/isalnum_l.c: New file.
* lib/is_l-impl.h: New file.
* m4/isalnum_l.m4: New file.
* m4/ctype_h.m4 (gl_CTYPE_H): Test for isalnum_l.
(gl_CTYPE_H_REQUIRE_DEFAULTS): Initialize GNULIB_ISALNUM_L.
(gl_CTYPE_H_DEFAULTS): Initialize HAVE_ISALNUM_L.
* modules/ctype-h (Makefile.am): Substitute GNULIB_ISALNUM_L,
HAVE_ISALNUM_L.
* modules/isalnum_l: New file.
* tests/test-ctype-h-c++.cc: Check declaration of isalnum_l.
* doc/posix-functions/isalnum_l.texi: Mention the new module.

ChangeLog
doc/posix-functions/isalnum_l.texi
lib/ctype.in.h
lib/is_l-impl.h [new file with mode: 0644]
lib/isalnum_l.c [new file with mode: 0644]
m4/ctype_h.m4
m4/isalnum_l.m4 [new file with mode: 0644]
modules/ctype-h
modules/isalnum_l [new file with mode: 0644]
tests/test-ctype-h-c++.cc

index 56a0f207447340c01264227a0385b89c3c1e6362..6e9c103bad3f8a96a69f3275009f6a049a4a0b77 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2025-02-14  Bruno Haible  <bruno@clisp.org>
+
+       isalnum_l: New module.
+       * lib/ctype.in.h: Include <locale.h>.
+       (isalnum_l): New declaration.
+       * lib/isalnum_l.c: New file.
+       * lib/is_l-impl.h: New file.
+       * m4/isalnum_l.m4: New file.
+       * m4/ctype_h.m4 (gl_CTYPE_H): Test for isalnum_l.
+       (gl_CTYPE_H_REQUIRE_DEFAULTS): Initialize GNULIB_ISALNUM_L.
+       (gl_CTYPE_H_DEFAULTS): Initialize HAVE_ISALNUM_L.
+       * modules/ctype-h (Makefile.am): Substitute GNULIB_ISALNUM_L,
+       HAVE_ISALNUM_L.
+       * modules/isalnum_l: New file.
+       * tests/test-ctype-h-c++.cc: Check declaration of isalnum_l.
+       * doc/posix-functions/isalnum_l.texi: Mention the new module.
+
 2025-02-14  Bruno Haible  <bruno@clisp.org>
 
        freelocale: Allow non-POSIX prototype on macOS.
index c56bdcd1f331d16a01d13c79afc0d72617e4728f..36c022369739366bd7dbd73a21d3c6f74bb154dc 100644 (file)
@@ -4,15 +4,16 @@
 
 POSIX specification:@* @url{https://pubs.opengroup.org/onlinepubs/9799919799/functions/isalnum_l.html}
 
-Gnulib module: ---
+Gnulib module: isalnum_l
+@mindex isalnum_l
 
 Portability problems 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
 
 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
index 13cfe60ffd5fd4ad2f7a1773642e9341df63d5f6..1ca6437c82b737b8a6c0fa79d903b4f2eb7d52d3 100644 (file)
 #endif
 @PRAGMA_COLUMNS@
 
+/* On Solaris 11 OmniOS, we cannot include <locale.h> until after <wchar.h> has
+   been entirely included.  That is because
+     - <locale.h> includes <xlocale.h>, which makes use of the mbstate_t type.
+     - <wchar.h> includes <iso/wchar_iso.h>, which includes <ctype.h> *before*
+       defining mbstate_t, WEOF, etc.  */
+#if defined __sun && defined _ISO_WCHAR_ISO_H && !defined WEOF
+/* We're in the middle of including <iso/wchar_iso.h>.
+   Include just the original <ctype.h>.  */
+
+#@INCLUDE_NEXT@ @NEXT_CTYPE_H@
+
+#else
+
 /* Include the original <ctype.h>.  */
 /* The include_next requires a split double-inclusion guard.  */
 #@INCLUDE_NEXT@ @NEXT_CTYPE_H@
  #error "Please include config.h first."
 #endif
 
+#if @GNULIB_ISALNUM_L@
+/* Get locale_t.  */
+# include <locale.h>
+#endif
+
 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here.  */
 
 /* The definition of _GL_WARN_ON_USE is copied here.  */
 
+/* Return non-zero if c is alphanumeric.  */
+#if @GNULIB_ISALNUM_L@
+# if !@HAVE_ISALNUM_L@
+_GL_FUNCDECL_SYS (isalnum_l, int, (int c, locale_t locale),
+                                  _GL_ARG_NONNULL ((2)));
+# endif
+_GL_CXXALIAS_SYS (isalnum_l, int, (int c, locale_t locale));
+_GL_CXXALIASWARN (isalnum_l);
+#elif defined GNULIB_POSIXCHECK
+# undef isalnum_l
+# if HAVE_RAW_DECL_ISALNUM_L
+_GL_WARN_ON_USE (isalnum_l, "isalnum_l is unportable - "
+                 "use gnulib module isalnum_l for portability");
+# endif
+#endif
+
 /* Return non-zero if c is a blank, i.e. a space or tab character.  */
 #if @GNULIB_ISBLANK@
 # if !@HAVE_ISBLANK@
@@ -59,4 +93,5 @@ _GL_WARN_ON_USE (isblank, "isblank is unportable - "
 #endif
 
 #endif /* _@GUARD_PREFIX@_CTYPE_H */
+#endif
 #endif /* _@GUARD_PREFIX@_CTYPE_H */
diff --git a/lib/is_l-impl.h b/lib/is_l-impl.h
new file mode 100644 (file)
index 0000000..27de6de
--- /dev/null
@@ -0,0 +1,52 @@
+/* Test whether a single-byte character belongs to a specific character class.
+   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 <https://www.gnu.org/licenses/>.  */
+
+/* Written by Bruno Haible <bruno@clisp.org>, 2025.  */
+
+#include <locale.h>
+#include <stdio.h>
+
+int
+FUNC (int c, locale_t locale)
+{
+  struct gl_locale_category_t *plc =
+    &locale->category[gl_log2_lc_mask (LC_CTYPE)];
+  if (plc->is_c_locale)
+    /* Implementation for the "C" locale.  */
+    return C_FUNC (c);
+#if HAVE_WINDOWS_LOCALE_T
+# ifdef __MINGW32__
+  /* mingw mistreats EOF by casting the argument to 'unsigned char'.
+     <https://sourceforge.net/p/mingw-w64/mingw-w64/ci/b633824ecafdf52a76e6a205e6776b182978720d>  */
+  if (c == EOF)
+    return 0;
+# endif
+  return WINDOWS_FUNC (c, plc->system_locale);
+#else
+  /* Implementation for the global locale.  */
+  {
+    int ret;
+# if HAVE_WORKING_USELOCALE
+    locale_t saved_locale = uselocale (LC_GLOBAL_LOCALE);
+# endif
+    ret = GLOBAL_FUNC (c);
+# if HAVE_WORKING_USELOCALE
+    uselocale (saved_locale);
+# endif
+    return ret;
+  }
+#endif
+}
diff --git a/lib/isalnum_l.c b/lib/isalnum_l.c
new file mode 100644 (file)
index 0000000..aee1d35
--- /dev/null
@@ -0,0 +1,31 @@
+/* Test whether a single-byte character is alphanumeric.
+   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 <https://www.gnu.org/licenses/>.  */
+
+/* Written by Bruno Haible <bruno@clisp.org>, 2025.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include <ctype.h>
+
+#define FUNC isalnum_l
+#define GLOBAL_FUNC isalnum
+#define C_FUNC(c) \
+  ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9'))
+/* Documentation:
+   <https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/isalnum-iswalnum-isalnum-l-iswalnum-l>  */
+#define WINDOWS_FUNC _isalnum_l
+#include "is_l-impl.h"
index 801b4ff687900a33e9101353b0034e91404ee171..c97a7b93521fe1032f5da4d31d6f21bd98cdaa21 100644 (file)
@@ -1,5 +1,5 @@
 # ctype_h.m4
-# serial 9
+# serial 10
 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 <ctype.h>
-    ]], [isblank])
+    ]], [isalnum_l isblank])
 ])
 
 # gl_CTYPE_MODULE_INDICATOR([modulename])
@@ -36,6 +36,7 @@ AC_DEFUN([gl_CTYPE_MODULE_INDICATOR],
 AC_DEFUN([gl_CTYPE_H_REQUIRE_DEFAULTS],
 [
   m4_defun(GL_MODULE_INDICATOR_PREFIX[_CTYPE_H_MODULE_INDICATOR_DEFAULTS], [
+    gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ISALNUM_L])
     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ISBLANK])
   ])
   m4_require(GL_MODULE_INDICATOR_PREFIX[_CTYPE_H_MODULE_INDICATOR_DEFAULTS])
@@ -45,5 +46,6 @@ AC_DEFUN([gl_CTYPE_H_REQUIRE_DEFAULTS],
 AC_DEFUN([gl_CTYPE_H_DEFAULTS],
 [
   dnl Assume proper GNU behavior unless another module says otherwise.
-  HAVE_ISBLANK=1;   AC_SUBST([HAVE_ISBLANK])
+  HAVE_ISALNUM_L=1;   AC_SUBST([HAVE_ISALNUM_L])
+  HAVE_ISBLANK=1;     AC_SUBST([HAVE_ISBLANK])
 ])
diff --git a/m4/isalnum_l.m4 b/m4/isalnum_l.m4
new file mode 100644 (file)
index 0000000..cf613db
--- /dev/null
@@ -0,0 +1,23 @@
+# isalnum_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_ISALNUM_L],
+[
+  AC_REQUIRE([gl_CTYPE_H_DEFAULTS])
+
+  dnl Persuade glibc <ctype.h> to declare isalnum_l().
+  AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
+
+  AC_CHECK_FUNCS_ONCE([isalnum_l])
+  if test $ac_cv_func_isalnum_l = no; then
+    HAVE_ISALNUM_L=0
+  fi
+
+  dnl Prerequisites of lib/isalnum_l.c.
+  AC_REQUIRE([gt_FUNC_USELOCALE])
+])
index ca228001636a11a2220ffdb03950664f957c8803..a7f04a3621e584a137a430cd3cf7c68bc6aaaff7 100644 (file)
@@ -30,7 +30,9 @@ ctype.h: ctype.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(WARN_ON_USE_H)
              -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
              -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
              -e 's|@''NEXT_CTYPE_H''@|$(NEXT_CTYPE_H)|g' \
+             -e 's/@''GNULIB_ISALNUM_L''@/$(GNULIB_ISALNUM_L)/g' \
              -e 's/@''GNULIB_ISBLANK''@/$(GNULIB_ISBLANK)/g' \
+             -e 's/@''HAVE_ISALNUM_L''@/$(HAVE_ISALNUM_L)/g' \
              -e 's/@''HAVE_ISBLANK''@/$(HAVE_ISBLANK)/g' \
              -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
              -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
diff --git a/modules/isalnum_l b/modules/isalnum_l
new file mode 100644 (file)
index 0000000..f4ce7b8
--- /dev/null
@@ -0,0 +1,33 @@
+Description:
+isalnum_l() function: test whether a single-byte character is alphanumeric.
+
+Files:
+lib/isalnum_l.c
+lib/is_l-impl.h
+m4/isalnum_l.m4
+m4/intl-thread-locale.m4
+
+Depends-on:
+ctype-h
+locale-h
+extensions
+
+configure.ac:
+gl_FUNC_ISALNUM_L
+gl_CONDITIONAL([GL_COND_OBJ_ISALNUM_L], [test $HAVE_ISALNUM_L = 0])
+gl_MODULE_INDICATOR([isalnum_l])
+gl_CTYPE_MODULE_INDICATOR([isalnum_l])
+
+Makefile.am:
+if GL_COND_OBJ_ISALNUM_L
+lib_SOURCES += isalnum_l.c
+endif
+
+Include:
+<ctype.h>
+
+License:
+LGPLv2+
+
+Maintainer:
+all
index 395cc59286840607d35835bc7361f6fc8f5da35d..99d6bd43b7a10a0b45adb6cba8a053e4b34cd3c9 100644 (file)
 #include "signature.h"
 
 
+#if GNULIB_TEST_ISALNUM_L
+SIGNATURE_CHECK (GNULIB_NAMESPACE::isalnum_l, int, (int, locale-t));
+#endif
+
 #if 0
 SIGNATURE_CHECK (GNULIB_NAMESPACE::isblank, int, (int));
 #endif