]> Savannah Git Hosting - gnulib.git/commitdiff
iswpunct: New module.
authorBruno Haible <bruno@clisp.org>
Wed, 30 Aug 2023 00:18:06 +0000 (02:18 +0200)
committerBruno Haible <bruno@clisp.org>
Wed, 30 Aug 2023 00:18:20 +0000 (02:18 +0200)
* lib/wctype.in.h (iswpunct): New declaration.
* lib/iswpunct.c: New file.
* m4/iswpunct.m4: New file.
* m4/wctype_h.m4 (gl_WCTYPE_H_REQUIRE_DEFAULTS): Initialize
GNULIB_ISWPUNCT.
(gl_WCTYPE_H_DEFAULTS): Initialize REPLACE_ISWPUNCT.
* modules/wctype-h (Makefile.am): Substitute GNULIB_ISWPUNCT,
REPLACE_ISWPUNCT.
* modules/iswpunct: New file.
* doc/posix-functions/iswpunct.texi: Mention the new module.

ChangeLog
doc/posix-functions/iswpunct.texi
lib/iswpunct.c [new file with mode: 0644]
lib/wctype.in.h
m4/iswpunct.m4 [new file with mode: 0644]
m4/wctype_h.m4
modules/iswpunct [new file with mode: 0644]
modules/wctype-h

index 3824fd0ed4a6f51b6592c774184dfbdb127345fe..abb5917a766d6f1e01f2e88ca3fe6e48add843a9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
 2023-08-29  Bruno Haible  <bruno@clisp.org>
 
+       iswpunct: New module.
+       * lib/wctype.in.h (iswpunct): New declaration.
+       * lib/iswpunct.c: New file.
+       * m4/iswpunct.m4: New file.
+       * m4/wctype_h.m4 (gl_WCTYPE_H_REQUIRE_DEFAULTS): Initialize
+       GNULIB_ISWPUNCT.
+       (gl_WCTYPE_H_DEFAULTS): Initialize REPLACE_ISWPUNCT.
+       * modules/wctype-h (Makefile.am): Substitute GNULIB_ISWPUNCT,
+       REPLACE_ISWPUNCT.
+       * modules/iswpunct: New file.
+       * doc/posix-functions/iswpunct.texi: Mention the new module.
+
        wctype-h tests: Add more tests.
        * tests/test-wctype-h.c (main): Add a sanity check of iswpunct.
 
index bc0e65ac93d79d6feef14e0874c9e95fcdfd87bd..663f2cca616cfbde80c3132edf451fb4fcd7a363 100644 (file)
@@ -4,7 +4,7 @@
 
 POSIX specification:@* @url{https://pubs.opengroup.org/onlinepubs/9699919799/functions/iswpunct.html}
 
-Gnulib module: wctype-h
+Gnulib module: iswpunct
 
 Portability problems fixed by Gnulib:
 @itemize
@@ -15,6 +15,12 @@ Minix 3.1.8.
 This function cannot be called from plain inline or extern inline functions
 on some platforms:
 OS X 10.8.
+@item
+This function is inconsistent with the @code{ispunct} function, because it
+returns false for the characters @code{'$'}, @code{'+'}, @code{'<'},
+@code{'='}, @code{'>'}, @code{'^'}, @code{'`'} , @code{'|'}, @code{'~'}
+on some platforms:
+Android 11.
 @end itemize
 
 Portability problems not fixed by Gnulib:
diff --git a/lib/iswpunct.c b/lib/iswpunct.c
new file mode 100644 (file)
index 0000000..0d60cb7
--- /dev/null
@@ -0,0 +1,33 @@
+/* Test wide character for being a punctuation or symbol character.
+   Copyright (C) 2023 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/>.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include <wctype.h>
+
+#include <ctype.h>
+
+int
+iswpunct (wint_t wc)
+#undef iswpunct
+{
+#if defined __ANDROID__
+  if ((unsigned int) wc < 128)
+    return ispunct ((unsigned int) wc);
+#endif
+  return iswpunct (wc);
+}
index fd52715a8ac04056c2d56dd6c435375b302900fd..6f1e7ef1498b3fc81c5ec3ab909b8196d594d5ee 100644 (file)
@@ -133,7 +133,7 @@ typedef unsigned int rpl_wint_t;
    Linux libc5 has <wctype.h> and the functions but they are broken.
    mingw and MSVC have <wctype.h> and the functions but they take a wchar_t
    as argument, not an rpl_wint_t.  Additionally, the mingw iswprint function
-   is broken.
+   and the Android iswpunct function are broken.
    Assume all 11 functions (all isw* except iswblank) are implemented the
    same way, or not at all.  */
 # if ! @HAVE_ISWCNTRL@ || @REPLACE_ISWCNTRL@
@@ -494,6 +494,16 @@ _GL_FUNCDECL_RPL (iswdigit, int, (wint_t wc));
 #   endif
 #  endif
 
+#  if @GNULIB_ISWPUNCT@
+#   if @REPLACE_ISWPUNCT@
+#    if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#     undef iswpunct
+#     define iswpunct rpl_iswpunct
+#    endif
+_GL_FUNCDECL_RPL (iswpunct, int, (wint_t wc));
+#   endif
+#  endif
+
 #  if @GNULIB_ISWXDIGIT@
 #   if @REPLACE_ISWXDIGIT@
 #    if !(defined __cplusplus && defined GNULIB_NAMESPACE)
diff --git a/m4/iswpunct.m4 b/m4/iswpunct.m4
new file mode 100644 (file)
index 0000000..1469115
--- /dev/null
@@ -0,0 +1,47 @@
+# iswpunct.m4 serial 1
+dnl Copyright (C) 2023 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.
+
+AC_DEFUN([gl_FUNC_ISWPUNCT],
+[
+  AC_REQUIRE([gl_WCTYPE_H_DEFAULTS])
+  AC_REQUIRE([gl_WCTYPE_H])
+
+  if test $HAVE_ISWCNTRL = 0 || test $REPLACE_ISWCNTRL = 1; then
+    dnl <wctype.h> redefines iswpunct already.
+    REPLACE_ISWPUNCT="$REPLACE_ISWCNTRL"
+  else
+    AC_CACHE_CHECK([whether iswpunct is consistent with ispunct],
+      [gl_cv_func_iswpunct_works],
+      [AC_RUN_IFELSE(
+         [AC_LANG_SOURCE([[
+#include <ctype.h>
+#include <wchar.h>
+#include <wctype.h>
+int
+main (int argc, char *argv[])
+{
+  int result = 0;
+  /* This fails on Android 11.  */
+  if ((! iswpunct ('\`')) != (! ispunct ('\`')))
+    result |= 1;
+  return result;
+}]])],
+         [gl_cv_func_iswpunct_works=yes],
+         [gl_cv_func_iswpunct_works=no],
+         [case "$host_os" in
+            # Guess no on Android.
+            android*) gl_cv_func_iswpunct_works="guessing no" ;;
+            # Guess yes otherwise.
+            *)        gl_cv_func_iswpunct_works="guessing yes" ;;
+          esac
+         ])
+      ])
+    case "$gl_cv_func_iswpunct_works" in
+      *yes) ;;
+      *) REPLACE_ISWPUNCT=1 ;;
+    esac
+  fi
+])
index 43a2d9cf10a7497ec3a1e391ae368e83f49e9d31..ac9c35b2da84194524208a4719084f57b2710e78 100644 (file)
@@ -1,4 +1,4 @@
-# wctype_h.m4 serial 32
+# wctype_h.m4 serial 33
 
 dnl A placeholder for ISO C99 <wctype.h>, for platforms that lack it.
 
@@ -178,6 +178,7 @@ AC_DEFUN([gl_WCTYPE_H_REQUIRE_DEFAULTS],
   m4_defun(GL_MODULE_INDICATOR_PREFIX[_WCTYPE_H_MODULE_INDICATOR_DEFAULTS], [
     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ISWBLANK])
     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ISWDIGIT])
+    gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ISWPUNCT])
     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ISWXDIGIT])
     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCTYPE])
     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ISWCTYPE])
@@ -196,6 +197,7 @@ AC_DEFUN([gl_WCTYPE_H_DEFAULTS],
   HAVE_WCTRANS_T=1;     AC_SUBST([HAVE_WCTRANS_T])
   REPLACE_ISWBLANK=0;   AC_SUBST([REPLACE_ISWBLANK])
   REPLACE_ISWDIGIT=0;   AC_SUBST([REPLACE_ISWDIGIT])
+  REPLACE_ISWPUNCT=0;   AC_SUBST([REPLACE_ISWPUNCT])
   REPLACE_ISWXDIGIT=0;  AC_SUBST([REPLACE_ISWXDIGIT])
   REPLACE_WCTRANS=0;    AC_SUBST([REPLACE_WCTRANS])
   REPLACE_WCTYPE=0;     AC_SUBST([REPLACE_WCTYPE])
diff --git a/modules/iswpunct b/modules/iswpunct
new file mode 100644 (file)
index 0000000..0abeb94
--- /dev/null
@@ -0,0 +1,30 @@
+Description:
+iswpunct() function: test wide character for being a punctuation or symbol
+character.
+
+Files:
+lib/iswpunct.c
+m4/iswpunct.m4
+
+Depends-on:
+wctype-h
+
+configure.ac:
+gl_FUNC_ISWPUNCT
+gl_CONDITIONAL([GL_COND_OBJ_ISWPUNCT],
+               [! { test $HAVE_ISWCNTRL = 0 || test $REPLACE_ISWCNTRL = 1; } && test $REPLACE_ISWPUNCT = 1])
+gl_WCTYPE_MODULE_INDICATOR([iswpunct])
+
+Makefile.am:
+if GL_COND_OBJ_ISWPUNCT
+lib_SOURCES += iswpunct.c
+endif
+
+Include:
+<wctype.h>
+
+License:
+LGPLv2+
+
+Maintainer:
+Bruno Haible
index 99aba62d90e5bdfb67b56e00c2b202c8c64d805b..682ef51be0f57366bda72b830328f38d0b235ce7 100644 (file)
@@ -39,6 +39,7 @@ wctype.h: wctype.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H
              -e 's/@''GNULIBHEADERS_OVERRIDE_WINT_T''@/$(GNULIBHEADERS_OVERRIDE_WINT_T)/g' \
              -e 's/@''GNULIB_ISWBLANK''@/$(GNULIB_ISWBLANK)/g' \
              -e 's/@''GNULIB_ISWDIGIT''@/$(GNULIB_ISWDIGIT)/g' \
+             -e 's/@''GNULIB_ISWPUNCT''@/$(GNULIB_ISWPUNCT)/g' \
              -e 's/@''GNULIB_ISWXDIGIT''@/$(GNULIB_ISWXDIGIT)/g' \
              -e 's/@''GNULIB_WCTYPE''@/$(GNULIB_WCTYPE)/g' \
              -e 's/@''GNULIB_ISWCTYPE''@/$(GNULIB_ISWCTYPE)/g' \
@@ -51,6 +52,7 @@ wctype.h: wctype.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H
              -e 's/@''HAVE_WINT_T''@/$(HAVE_WINT_T)/g' \
              -e 's/@''REPLACE_ISWBLANK''@/$(REPLACE_ISWBLANK)/g' \
              -e 's/@''REPLACE_ISWDIGIT''@/$(REPLACE_ISWDIGIT)/g' \
+             -e 's/@''REPLACE_ISWPUNCT''@/$(REPLACE_ISWPUNCT)/g' \
              -e 's/@''REPLACE_ISWXDIGIT''@/$(REPLACE_ISWXDIGIT)/g' \
              -e 's/@''REPLACE_ISWCNTRL''@/$(REPLACE_ISWCNTRL)/g' \
              -e 's/@''REPLACE_TOWLOWER''@/$(REPLACE_TOWLOWER)/g' \