]> Savannah Git Hosting - gnulib.git/commitdiff
tolower_l: New module.
authorBruno Haible <bruno@clisp.org>
Sun, 16 Feb 2025 05:45:57 +0000 (06:45 +0100)
committerBruno Haible <bruno@clisp.org>
Sun, 16 Feb 2025 06:57:06 +0000 (07:57 +0100)
* lib/ctype.in.h: (tolower_l): New declaration.
* lib/tolower_l.c: New file.
* lib/to_l-impl.h: New file.
* m4/tolower_l.m4: New file.
* m4/ctype_h.m4 (gl_CTYPE_H): Test for tolower_l.
(gl_CTYPE_H_REQUIRE_DEFAULTS): Initialize GNULIB_TOLOWER_L.
(gl_CTYPE_H_DEFAULTS): Initialize HAVE_TOLOWER_L.
* modules/ctype-h (Makefile.am): Substitute GNULIB_TOLOWER_L,
HAVE_TOLOWER_L.
* modules/tolower_l: New file.
* tests/test-ctype-h-c++.cc: Check declaration of tolower_l.
* doc/posix-functions/tolower_l.texi: Mention the new module.

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

index c489a34df6a86914200dae4ebe2e4b39c861759c..939915b2978004bba82057b28c9f072a4bd7e96b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2025-02-16  Bruno Haible  <bruno@clisp.org>
+
+       tolower_l: New module.
+       * lib/ctype.in.h: (tolower_l): New declaration.
+       * lib/tolower_l.c: New file.
+       * lib/to_l-impl.h: New file.
+       * m4/tolower_l.m4: New file.
+       * m4/ctype_h.m4 (gl_CTYPE_H): Test for tolower_l.
+       (gl_CTYPE_H_REQUIRE_DEFAULTS): Initialize GNULIB_TOLOWER_L.
+       (gl_CTYPE_H_DEFAULTS): Initialize HAVE_TOLOWER_L.
+       * modules/ctype-h (Makefile.am): Substitute GNULIB_TOLOWER_L,
+       HAVE_TOLOWER_L.
+       * modules/tolower_l: New file.
+       * tests/test-ctype-h-c++.cc: Check declaration of tolower_l.
+       * doc/posix-functions/tolower_l.texi: Mention the new module.
+
 2025-02-15  Bruno Haible  <bruno@clisp.org>
 
        isxdigit_l: Add tests.
index 0a6dcb5df09535659566c535161a868e5fd07b59..bf0c010d6c4e58fc2ee4db7a1ecedc3e9cf812b1 100644 (file)
@@ -4,15 +4,16 @@
 
 POSIX specification:@* @url{https://pubs.opengroup.org/onlinepubs/9799919799/functions/tolower_l.html}
 
-Gnulib module: ---
+Gnulib module: tolower_l
+@mindex tolower_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
index 0aa517539758b59b4cdda76f92fd415730a05011..e5259709f00240131421abd209e1c8f0e7c676db 100644 (file)
@@ -57,7 +57,8 @@
 #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_ISXDIGIT_L@)
+     || @GNULIB_ISSPACE_L@ || @GNULIB_ISUPPER_L@ || @GNULIB_ISXDIGIT_L@ \
+     || @GNULIB_TOLOWER_L@)
 /* Get locale_t.  */
 # include <locale.h>
 #endif
@@ -295,6 +296,24 @@ _GL_WARN_ON_USE (isxdigit_l, "isxdigit_l is unportable - "
 # endif
 #endif
 
+/* Map c to lowercase.  */
+#if @GNULIB_TOLOWER_L@
+# if !@HAVE_TOLOWER_L@
+_GL_FUNCDECL_SYS (tolower_l, int, (int c, locale_t locale),
+                                  _GL_ARG_NONNULL ((2)));
+# endif
+_GL_CXXALIAS_SYS (tolower_l, int, (int c, locale_t locale));
+# if __GLIBC__ >= 2
+_GL_CXXALIASWARN (tolower_l);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef tolower_l
+# if HAVE_RAW_DECL_TOLOWER_L
+_GL_WARN_ON_USE (tolower_l, "tolower_l is unportable - "
+                 "use gnulib module tolower_l for portability");
+# endif
+#endif
+
 #endif /* _@GUARD_PREFIX@_CTYPE_H */
 #endif
 #endif /* _@GUARD_PREFIX@_CTYPE_H */
diff --git a/lib/to_l-impl.h b/lib/to_l-impl.h
new file mode 100644 (file)
index 0000000..63816ae
--- /dev/null
@@ -0,0 +1,51 @@
+/* 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
+# ifndef _UCRT
+  /* The old MSVCRT mistreats EOF.  */
+  if (c == EOF)
+    return c;
+# 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/tolower_l.c b/lib/tolower_l.c
new file mode 100644 (file)
index 0000000..eb074ee
--- /dev/null
@@ -0,0 +1,31 @@
+/* Mapping a single-byte character to lowercase.
+   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 tolower_l
+#define GLOBAL_FUNC tolower
+#define C_FUNC(c) \
+  (c >= 'A' && c <= 'Z' ? c - 'A' + 'a' : c)
+/* Documentation:
+   <https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/tolower-tolower-towlower-tolower-l-towlower-l>  */
+#define WINDOWS_FUNC _tolower_l
+#include "to_l-impl.h"
index 972144c93c96109daf3b46266635ffa562e6cf06..fa459e2b62f1d3c24fc53df5ee1c60fd22a7b0f9 100644 (file)
@@ -1,5 +1,5 @@
 # ctype_h.m4
-# serial 21
+# serial 22
 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,8 @@ AC_DEFUN_ONCE([gl_CTYPE_H],
   dnl corresponding gnulib module is not in use.
   gl_WARN_ON_USE_PREPARE([[#include <ctype.h>
     ]], [isalnum_l isalpha_l isblank isblank_l iscntrl_l isdigit_l isgraph_l
-    islower_l isprint_l ispunct_l isspace_l isupper_l isxdigit_l])
+    islower_l isprint_l ispunct_l isspace_l isupper_l isxdigit_l
+    tolower_l])
 ])
 
 # gl_CTYPE_MODULE_INDICATOR([modulename])
@@ -50,6 +51,7 @@ AC_DEFUN([gl_CTYPE_H_REQUIRE_DEFAULTS],
     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ISSPACE_L])
     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ISUPPER_L])
     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ISXDIGIT_L])
+    gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TOLOWER_L])
   ])
   m4_require(GL_MODULE_INDICATOR_PREFIX[_CTYPE_H_MODULE_INDICATOR_DEFAULTS])
   AC_REQUIRE([gl_CTYPE_H_DEFAULTS])
@@ -71,4 +73,5 @@ AC_DEFUN([gl_CTYPE_H_DEFAULTS],
   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])
+  HAVE_TOLOWER_L=1;   AC_SUBST([HAVE_TOLOWER_L])
 ])
diff --git a/m4/tolower_l.m4 b/m4/tolower_l.m4
new file mode 100644 (file)
index 0000000..5859c60
--- /dev/null
@@ -0,0 +1,23 @@
+# tolower_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_TOLOWER_L],
+[
+  AC_REQUIRE([gl_CTYPE_H_DEFAULTS])
+
+  dnl Persuade glibc <ctype.h> to declare tolower_l().
+  AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
+
+  AC_CHECK_FUNCS_ONCE([tolower_l])
+  if test $ac_cv_func_tolower_l = no; then
+    HAVE_TOLOWER_L=0
+  fi
+
+  dnl Prerequisites of lib/tolower_l.c.
+  AC_REQUIRE([gt_FUNC_USELOCALE])
+])
index b5f428bb442613aa676492b1d5d0eeb723eaa430..cf36d5e1dacd3abb0b3983175c711448e51eef4b 100644 (file)
@@ -43,6 +43,7 @@ ctype.h: ctype.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(WARN_ON_USE_H)
              -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/@''GNULIB_TOLOWER_L''@/$(GNULIB_TOLOWER_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' \
@@ -56,6 +57,7 @@ ctype.h: ctype.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(WARN_ON_USE_H)
              -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 's/@''HAVE_TOLOWER_L''@/$(HAVE_TOLOWER_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/tolower_l b/modules/tolower_l
new file mode 100644 (file)
index 0000000..c5387e5
--- /dev/null
@@ -0,0 +1,33 @@
+Description:
+tolower_l() function: map a single-byte character to lowercase.
+
+Files:
+lib/tolower_l.c
+lib/to_l-impl.h
+m4/tolower_l.m4
+m4/intl-thread-locale.m4
+
+Depends-on:
+ctype-h
+locale-h
+extensions
+
+configure.ac:
+gl_FUNC_TOLOWER_L
+gl_CONDITIONAL([GL_COND_OBJ_TOLOWER_L], [test $HAVE_TOLOWER_L = 0])
+gl_MODULE_INDICATOR([tolower_l])
+gl_CTYPE_MODULE_INDICATOR([tolower_l])
+
+Makefile.am:
+if GL_COND_OBJ_TOLOWER_L
+lib_SOURCES += tolower_l.c
+endif
+
+Include:
+<ctype.h>
+
+License:
+LGPLv2+
+
+Maintainer:
+all
index cce73591e4ce863b4e12e4c90e606a191ed59fce..578e99af314bc0828e5aa28e541135a274092608 100644 (file)
@@ -76,6 +76,10 @@ SIGNATURE_CHECK (GNULIB_NAMESPACE::isupper_l, int, (int, locale_t));
 SIGNATURE_CHECK (GNULIB_NAMESPACE::isxdigit_l, int, (int, locale_t));
 #endif
 
+#if GNULIB_TEST_TOLOWER_L
+SIGNATURE_CHECK (GNULIB_NAMESPACE::tolower_l, int, (int, locale_t));
+#endif
+
 
 int
 main ()