]> Savannah Git Hosting - gnulib.git/commitdiff
mbsnrtoc32s: New module.
authorBruno Haible <bruno@clisp.org>
Sun, 5 Jan 2020 01:32:18 +0000 (02:32 +0100)
committerBruno Haible <bruno@clisp.org>
Sun, 5 Jan 2020 01:32:18 +0000 (02:32 +0100)
* lib/uchar.in.h (mbsnrtoc32s): New declaration.
* lib/mbsnrtowcs-impl.h: Parameterize: Use macros FUNC, DCHAR_T,
INTERNAL_STATE, MBRTOWC.
* lib/mbsnrtowcs.c (FUNC, DCHAR_T, INTERNAL_STATE, MBRTOWC): New macros.
* lib/mbsnrtoc32s.c: New file.
* m4/uchar.m4 (gl_UCHAR_H_DEFAULTS): Initialize GNULIB_MBSNRTOC32S.
* modules/uchar (Makefile.am): Substitute GNULIB_MBSNRTOC32S.
* modules/mbsnrtoc32s: New file.
* tests/test-uchar-c++.cc: Test the signature of mbsnrtoc32s.
* doc/posix-functions/mbsnrtowcs.texi: Mention the new module.

ChangeLog
doc/posix-functions/mbsnrtowcs.texi
lib/mbsnrtoc32s.c [new file with mode: 0644]
lib/mbsnrtowcs-impl.h
lib/mbsnrtowcs.c
lib/uchar.in.h
m4/uchar.m4
modules/mbsnrtoc32s [new file with mode: 0644]
modules/uchar
tests/test-uchar-c++.cc

index 282543721e6fd66dfa7593780d2d1bc2e2786884..fb16eee2c84feef71fb055401d5ecc60549ab39e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2020-01-04  Bruno Haible  <bruno@clisp.org>
+
+       mbsnrtoc32s: New module.
+       * lib/uchar.in.h (mbsnrtoc32s): New declaration.
+       * lib/mbsnrtowcs-impl.h: Parameterize: Use macros FUNC, DCHAR_T,
+       INTERNAL_STATE, MBRTOWC.
+       * lib/mbsnrtowcs.c (FUNC, DCHAR_T, INTERNAL_STATE, MBRTOWC): New macros.
+       * lib/mbsnrtoc32s.c: New file.
+       * m4/uchar.m4 (gl_UCHAR_H_DEFAULTS): Initialize GNULIB_MBSNRTOC32S.
+       * modules/uchar (Makefile.am): Substitute GNULIB_MBSNRTOC32S.
+       * modules/mbsnrtoc32s: New file.
+       * tests/test-uchar-c++.cc: Test the signature of mbsnrtoc32s.
+       * doc/posix-functions/mbsnrtowcs.texi: Mention the new module.
+
 2020-01-04  Bruno Haible  <bruno@clisp.org>
 
        mbsrtoc32s tests: Enhance test.
index bd7911bf4e6d21c7bb5f68a76e699dcf50d48e2f..c6defd2c20663c9b5baa9b1e8441ba602d4398f7 100644 (file)
@@ -19,8 +19,11 @@ Solaris 11.4.
 Portability problems not fixed by Gnulib:
 @itemize
 @item
-On Windows and 32-bit AIX platforms, @code{wchar_t} is a 16-bit type and therefore cannot
-accommodate all Unicode characters.
+On Windows and 32-bit AIX platforms, @code{wchar_t} is a 16-bit type and
+therefore cannot accommodate all Unicode characters.
+However, the Gnulib function @code{mbsnrtoc32s}, provided by Gnulib module
+@code{mbsnrtoc32s}, operates on 32-bit wide characters and therefore does not
+have this limitation.
 @item
 The specification is not clear about whether this function should update the
 conversion state when the first argument (the destination pointer) is NULL.
diff --git a/lib/mbsnrtoc32s.c b/lib/mbsnrtoc32s.c
new file mode 100644 (file)
index 0000000..7ba0415
--- /dev/null
@@ -0,0 +1,63 @@
+/* Convert string to 32-bit wide string.
+   Copyright (C) 2020 Free Software Foundation, Inc.
+   Written by Bruno Haible <bruno@clisp.org>, 2020.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program 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 General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include <uchar.h>
+
+#include <wchar.h>
+
+#if _GL_LARGE_CHAR32_T
+
+/* For Cygwin >= 1.7 it would be possible to speed this up a bit by cutting
+   the source into chunks, calling mbsnrtowcs on a chunk, then u16_to_u32 on
+   the result, then proceed with the next chunk, and so on.
+   But speed is not critical here so far.  */
+
+/* Reuse the implementation of mbsnrtowcs with a different parameterization.  */
+
+# include <errno.h>
+# include <limits.h>
+# include <stdlib.h>
+
+# include "minmax.h"
+# include "strnlen1.h"
+
+extern mbstate_t _gl_mbsrtoc32s_state;
+
+# define FUNC mbsnrtoc32s
+# define DCHAR_T char32_t
+# define INTERNAL_STATE _gl_mbsrtoc32s_state
+# define MBRTOWC mbrtoc32
+# include "mbsnrtowcs-impl.h"
+
+#else
+/* char32_t and wchar_t are equivalent.  */
+
+# include "verify.h"
+
+verify (sizeof (char32_t) == sizeof (wchar_t));
+
+size_t
+mbsnrtoc32s (char32_t *dest, const char **srcp, size_t srclen, size_t len,
+             mbstate_t *ps)
+{
+  return mbsnrtowcs ((wchar_t *) dest, srcp, srclen, len, ps);
+}
+
+#endif
index 29ed8703554bf2ae7317f18c3c1f1da1f79a6ba5..ede6fea15780dc7eb903fc564a998d0363ac5af9 100644 (file)
    along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
 
 size_t
-mbsnrtowcs (wchar_t *dest, const char **srcp, size_t srclen, size_t len, mbstate_t *ps)
+FUNC (DCHAR_T *dest, const char **srcp, size_t srclen, size_t len, mbstate_t *ps)
 {
   if (ps == NULL)
-    ps = &_gl_mbsrtowcs_state;
+    ps = &INTERNAL_STATE;
   {
     const char *src = *srcp;
 
     if (dest != NULL)
       {
-        wchar_t *destptr = dest;
+        DCHAR_T *destptr = dest;
 
         for (; srclen > 0 && len > 0; destptr++, len--)
           {
@@ -46,7 +46,7 @@ mbsnrtowcs (wchar_t *dest, const char **srcp, size_t srclen, size_t len, mbstate
               src_avail = 4 + strnlen1 (src + 4, MIN (srclen, MB_LEN_MAX) - 4);
 
             /* Parse the next multibyte character.  */
-            ret = mbrtowc (destptr, src, src_avail, ps);
+            ret = MBRTOWC (destptr, src, src_avail, ps);
 
             if (ret == (size_t)(-2))
               /* Encountered a multibyte character that extends past a '\0' byte
@@ -94,7 +94,7 @@ mbsnrtowcs (wchar_t *dest, const char **srcp, size_t srclen, size_t len, mbstate
               src_avail = 4 + strnlen1 (src + 4, MIN (srclen, MB_LEN_MAX) - 4);
 
             /* Parse the next multibyte character.  */
-            ret = mbrtowc (NULL, src, src_avail, &state);
+            ret = MBRTOWC (NULL, src, src_avail, &state);
 
             if (ret == (size_t)(-2))
               /* Encountered a multibyte character that extends past a '\0' byte
index 2fa5c3eb134cb6c9f378f4aaf7edfbe95ec92d1f..63bac590de56909f31cb6fbe83d6daad6d84c535 100644 (file)
@@ -30,4 +30,8 @@
 
 extern mbstate_t _gl_mbsrtowcs_state;
 
+#define FUNC mbsnrtowcs
+#define DCHAR_T wchar_t
+#define INTERNAL_STATE _gl_mbsrtowcs_state
+#define MBRTOWC mbrtowc
 #include "mbsnrtowcs-impl.h"
index 318cf8ef64a0ef53bc2b4b16a7f73c45b0c0eed3..f31b18c50a59768f74f3df034033c1ade7a0694f 100644 (file)
@@ -107,6 +107,19 @@ _GL_WARN_ON_USE (mbrtoc32, "mbrtoc32 is not portable - "
 #endif
 
 
+/* Convert a string to a 32-bit wide string.  */
+#if @GNULIB_MBSNRTOC32S@
+_GL_FUNCDECL_SYS (mbsnrtoc32s, size_t,
+                  (char32_t *dest, const char **srcp, size_t srclen, size_t len,
+                   mbstate_t *ps)
+                  _GL_ARG_NONNULL ((2)));
+_GL_CXXALIAS_SYS (mbsnrtoc32s, size_t,
+                  (char32_t *dest, const char **srcp, size_t srclen, size_t len,
+                   mbstate_t *ps));
+_GL_CXXALIASWARN (mbsnrtoc32s);
+#endif
+
+
 /* Convert a string to a 32-bit wide string.  */
 #if @GNULIB_MBSRTOC32S@
 _GL_FUNCDECL_SYS (mbsrtoc32s, size_t,
index e92f5d6da635f82513c04c3eee4b3035cf252463..4e0f43a5e2652776a701a4e9a36aa17bb6703333 100644 (file)
@@ -1,4 +1,4 @@
-# uchar.m4 serial 6
+# uchar.m4 serial 7
 dnl Copyright (C) 2019-2020 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -50,6 +50,7 @@ AC_DEFUN([gl_UCHAR_H_DEFAULTS],
   GNULIB_BTOC32=0;           AC_SUBST([GNULIB_BTOC32])
   GNULIB_C32TOB=0;           AC_SUBST([GNULIB_C32TOB])
   GNULIB_MBRTOC32=0;         AC_SUBST([GNULIB_MBRTOC32])
+  GNULIB_MBSNRTOC32S=0;      AC_SUBST([GNULIB_MBSNRTOC32S])
   GNULIB_MBSRTOC32S=0;       AC_SUBST([GNULIB_MBSRTOC32S])
   dnl Assume proper GNU behavior unless another module says otherwise.
   HAVE_MBRTOC32=1;           AC_SUBST([HAVE_MBRTOC32])
diff --git a/modules/mbsnrtoc32s b/modules/mbsnrtoc32s
new file mode 100644 (file)
index 0000000..44784d8
--- /dev/null
@@ -0,0 +1,38 @@
+Description:
+mbsnrtoc32s() function: convert string to 32-bit wide string.
+
+Files:
+lib/mbsnrtoc32s.c
+lib/mbsnrtowcs-impl.h
+lib/mbsrtoc32s-state.c
+
+Depends-on:
+uchar
+wchar
+verify
+mbrtoc32        [test $SMALL_WCHAR_T = 1]
+minmax          [test $SMALL_WCHAR_T = 1]
+strnlen1        [test $SMALL_WCHAR_T = 1]
+mbsnrtowcs      [test $SMALL_WCHAR_T = 0]
+
+configure.ac:
+AC_REQUIRE([gl_UCHAR_H])
+if test $SMALL_WCHAR_T = 1; then
+  AC_LIBOBJ([mbsrtoc32s-state])
+fi
+gl_UCHAR_MODULE_INDICATOR([mbsnrtoc32s])
+
+Makefile.am:
+lib_SOURCES += mbsnrtoc32s.c
+
+Include:
+<uchar.h>
+
+Link:
+$(LIB_MBRTOWC)
+
+License:
+LGPL
+
+Maintainer:
+Bruno Haible
index 03101c1f073e3832080aac2902a3435b58eea119..a50eb5af7d75d2323f1d153dfc1ee40e8cb32969 100644 (file)
@@ -31,6 +31,7 @@ uchar.h: uchar.in.h $(top_builddir)/config.status $(CXXDEFS_H)
              -e 's/@''GNULIB_BTOC32''@/$(GNULIB_BTOC32)/g' \
              -e 's/@''GNULIB_C32TOB''@/$(GNULIB_C32TOB)/g' \
              -e 's/@''GNULIB_MBRTOC32''@/$(GNULIB_MBRTOC32)/g' \
+             -e 's/@''GNULIB_MBSNRTOC32S''@/$(GNULIB_MBSNRTOC32S)/g' \
              -e 's/@''GNULIB_MBSRTOC32S''@/$(GNULIB_MBSRTOC32S)/g' \
              -e 's|@''HAVE_MBRTOC32''@|$(HAVE_MBRTOC32)|g' \
              -e 's|@''REPLACE_MBRTOC32''@|$(REPLACE_MBRTOC32)|g' \
index a7132a13b2547988627c8ba06d4deef3ba2e847f..a630eec0e6de354b6df32047f6ce7afa06197531 100644 (file)
@@ -37,6 +37,12 @@ SIGNATURE_CHECK (GNULIB_NAMESPACE::mbrtoc32, size_t,
                  (char32_t *, const char *, size_t, mbstate_t *));
 #endif
 
+#if GNULIB_TEST_MBSNRTOC32S
+SIGNATURE_CHECK (GNULIB_NAMESPACE::mbsnrtoc32s, size_t,
+                 (char32_t *, const char **, size_t, size_t, mbstate_t *));
+
+#endif
+
 #if GNULIB_TEST_MBSRTOC32S
 SIGNATURE_CHECK (GNULIB_NAMESPACE::mbsrtoc32s, size_t,
                  (char32_t *, const char **, size_t, mbstate_t *));