From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS22989 209.51.188.0/24 X-Spam-Status: No, score=-2.9 required=3.0 tests=AWL,BAYES_00,BODY_8BITS, DKIM_INVALID,DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id DDBED1F885 for ; Fri, 10 Jan 2020 22:33:15 +0000 (UTC) Received: from localhost ([::1]:52492 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iq2qA-0005sp-Jy for normalperson@yhbt.net; Fri, 10 Jan 2020 17:33:14 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35808) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iq2q3-0005o5-3O for bug-gnulib@gnu.org; Fri, 10 Jan 2020 17:33:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iq2pz-0003Ct-Rb for bug-gnulib@gnu.org; Fri, 10 Jan 2020 17:33:06 -0500 Received: from mo6-p00-ob.smtp.rzone.de ([2a01:238:20a:202:5300::7]:30221) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iq2py-0002qG-SZ for bug-gnulib@gnu.org; Fri, 10 Jan 2020 17:33:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1578695579; s=strato-dkim-0002; d=clisp.org; h=Message-ID:Date:Subject:To:From:X-RZG-CLASS-ID:X-RZG-AUTH:From: Subject:Sender; bh=NjNM6Lv76UOCA/CeuijlrExKPpTIxZbBhfEm8fdSyCo=; b=MmGF69nQRz8iv1v+q9CxkQiF7UMjmAX6rA3zMj0xkSC5ejDwX1ZhUjmoQetFaPg4yg 2tJVSMqlw7V6GnAWzNJJUO1C090nYPShZi9kdxgNHwgXGkNN6SJg7Jjoiz/gjTo3ogop OSTLXQcOzpHyfg/Yg7jBfOP8/D1o3tzn4eBfrjC3cy6n+8S8iLg+7Z+F88ElQYM9B6db KrW3ldbQwvdeUay7ne/m5bphUrrIBENVpl6hUO2NQGQh2kCxN9b5aXKY7n0U6IiBSHuL oHibsA5HmMKiR3SQ3AMNZjJVuLnCrBPS+6uMboghGonZA1OS70wir8Tns7SmeMCzz2Dz JOfw== X-RZG-AUTH: ":Ln4Re0+Ic/6oZXR1YgKryK8brlshOcZlIWs+iCP5vnk6shH1CXj3Jn2jCTOwfujm0Q==" X-RZG-CLASS-ID: mo00 Received: from bruno.haible.de by smtp.strato.de (RZmta 46.1.4 DYNA|AUTH) with ESMTPSA id z0b9d9w0AMWwBOr (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (curve X9_62_prime256v1 with 256 ECDH bits, eq. 3072 bits RSA)) (Client did not present a certificate); Fri, 10 Jan 2020 23:32:58 +0100 (CET) From: Bruno Haible To: bug-gnulib@gnu.org Subject: new module 'c32snrtombs' Date: Fri, 10 Jan 2020 23:32:58 +0100 Message-ID: <2968818.kksLEGOFGp@omega> User-Agent: KMail/5.1.3 (Linux/4.4.0-171-generic; KDE/5.18.0; x86_64; ; ) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="nextPart9309935.kGTjJD2t88" Content-Transfer-Encoding: 7Bit X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a01:238:20a:202:5300::7 X-BeenThere: bug-gnulib@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Gnulib discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnulib-bounces+normalperson=yhbt.net@gnu.org Sender: "bug-gnulib" This is a multi-part message in MIME format. --nextPart9309935.kGTjJD2t88 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" The function c32snrtombs is like wcsnrtombs, except that it takes a char32_t[] string as argument instead of a wchar_t[] string. 2020-01-10 Bruno Haible c32snrtombs: Add tests. * tests/test-c32snrtombs.c: New file, based on tests/test-wcsnrtombs.c. * tests/test-c32snrtombs-1.sh: New file, based on tests/test-wcsnrtombs1.sh. * tests/test-c32snrtombs-2.sh: New file, based on tests/test-wcsnrtombs2.sh. * tests/test-c32snrtombs-3.sh: New file, based on tests/test-wcsnrtombs3.sh. * tests/test-c32snrtombs-4.sh: New file, based on tests/test-wcsnrtombs4.sh. * modules/c32snrtombs-tests: New file, based on modules/wcsnrtombs-tests. c32snrtombs: New module. * lib/uchar.in.h (c32snrtombs): New declaration. * lib/wcsnrtombs-impl.h: Parameterize: Use macros FUNC, SCHAR_T, INTERNAL_STATE, WCRTOMB. * lib/wcsnrtombs.c (FUNC, SCHAR_T, INTERNAL_STATE, WCRTOMB): New macros. * lib/c32snrtombs.c: New file. * m4/uchar.m4 (gl_UCHAR_H_DEFAULTS): Initialize GNULIB_C32SNRTOMBS. * modules/uchar (Makefile.am): Substitute GNULIB_C32SNRTOMBS. * modules/c32snrtombs: New file. * tests/test-uchar-c++.cc: Test the signature of c32snrtombs. * doc/posix-functions/wcsnrtombs.texi: Mention the new module. --nextPart9309935.kGTjJD2t88 Content-Disposition: attachment; filename="0001-c32snrtombs-New-module.patch" Content-Transfer-Encoding: 7Bit Content-Type: text/x-patch; charset="UTF-8"; name="0001-c32snrtombs-New-module.patch" >From 980b40b1d6464d3aa9e68d8a0c19009c6cdaf6fb Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Fri, 10 Jan 2020 23:28:47 +0100 Subject: [PATCH 1/2] c32snrtombs: New module. * lib/uchar.in.h (c32snrtombs): New declaration. * lib/wcsnrtombs-impl.h: Parameterize: Use macros FUNC, SCHAR_T, INTERNAL_STATE, WCRTOMB. * lib/wcsnrtombs.c (FUNC, SCHAR_T, INTERNAL_STATE, WCRTOMB): New macros. * lib/c32snrtombs.c: New file. * m4/uchar.m4 (gl_UCHAR_H_DEFAULTS): Initialize GNULIB_C32SNRTOMBS. * modules/uchar (Makefile.am): Substitute GNULIB_C32SNRTOMBS. * modules/c32snrtombs: New file. * tests/test-uchar-c++.cc: Test the signature of c32snrtombs. * doc/posix-functions/wcsnrtombs.texi: Mention the new module. --- ChangeLog | 14 ++++++++++ doc/posix-functions/wcsnrtombs.texi | 7 +++-- lib/c32snrtombs.c | 56 +++++++++++++++++++++++++++++++++++++ lib/uchar.in.h | 13 +++++++++ lib/wcsnrtombs-impl.h | 14 +++++----- lib/wcsnrtombs.c | 4 +++ m4/uchar.m4 | 3 +- modules/c32snrtombs | 31 ++++++++++++++++++++ modules/uchar | 1 + tests/test-uchar-c++.cc | 5 ++++ 10 files changed, 138 insertions(+), 10 deletions(-) create mode 100644 lib/c32snrtombs.c create mode 100644 modules/c32snrtombs diff --git a/ChangeLog b/ChangeLog index 53a1fb4..84bc7d2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2020-01-10 Bruno Haible + + c32snrtombs: New module. + * lib/uchar.in.h (c32snrtombs): New declaration. + * lib/wcsnrtombs-impl.h: Parameterize: Use macros FUNC, SCHAR_T, + INTERNAL_STATE, WCRTOMB. + * lib/wcsnrtombs.c (FUNC, SCHAR_T, INTERNAL_STATE, WCRTOMB): New macros. + * lib/c32snrtombs.c: New file. + * m4/uchar.m4 (gl_UCHAR_H_DEFAULTS): Initialize GNULIB_C32SNRTOMBS. + * modules/uchar (Makefile.am): Substitute GNULIB_C32SNRTOMBS. + * modules/c32snrtombs: New file. + * tests/test-uchar-c++.cc: Test the signature of c32snrtombs. + * doc/posix-functions/wcsnrtombs.texi: Mention the new module. + 2020-01-09 Bruno Haible c32srtombs: Add tests. diff --git a/doc/posix-functions/wcsnrtombs.texi b/doc/posix-functions/wcsnrtombs.texi index 4cdfc7a..1b5fc12 100644 --- a/doc/posix-functions/wcsnrtombs.texi +++ b/doc/posix-functions/wcsnrtombs.texi @@ -24,6 +24,9 @@ Solaris 11 OpenIndiana. 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{c32snrtombs}, provided by Gnulib module +@code{c32snrtombs}, operates on 32-bit wide characters and therefore does not +have this limitation. @end itemize diff --git a/lib/c32snrtombs.c b/lib/c32snrtombs.c new file mode 100644 index 0000000..bd47e30 --- /dev/null +++ b/lib/c32snrtombs.c @@ -0,0 +1,56 @@ +/* Convert 32-bit wide string to string. + Copyright (C) 2020 Free Software Foundation, Inc. + + 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 . */ + +/* Written by Bruno Haible , 2020. */ + +#include + +/* Specification. */ +#include + +#include + +#if (HAVE_WORKING_MBRTOC32 && !defined __GLIBC__) || _GL_LARGE_CHAR32_T +/* The char32_t encoding of a multibyte character may be different than its + wchar_t encoding, or char32_t is wider than wchar_t. */ + +# include +# include +# include + +extern mbstate_t _gl_c32srtombs_state; + +# define FUNC c32snrtombs +# define SCHAR_T char32_t +# define INTERNAL_STATE _gl_c32srtombs_state +# define WCRTOMB c32rtomb +# include "wcsnrtombs-impl.h" + +#else +/* char32_t and wchar_t are equivalent. */ + +# include "verify.h" + +verify (sizeof (char32_t) == sizeof (wchar_t)); + +size_t +c32snrtombs (char *dest, const char32_t **srcp, size_t srclen, size_t len, + mbstate_t *ps) +{ + return wcsnrtombs (dest, (const wchar_t **) srcp, srclen, len, ps); +} + +#endif diff --git a/lib/uchar.in.h b/lib/uchar.in.h index 75da254..a149f5a 100644 --- a/lib/uchar.in.h +++ b/lib/uchar.in.h @@ -94,6 +94,19 @@ _GL_WARN_ON_USE (mbrtoc32, "c32rtomb is not portable - " /* Convert a 32-bit wide string to a string. */ +#if @GNULIB_C32SNRTOMBS@ +_GL_FUNCDECL_SYS (c32snrtombs, size_t, + (char *dest, const char32_t **srcp, size_t srclen, size_t len, + mbstate_t *ps) + _GL_ARG_NONNULL ((2))); +_GL_CXXALIAS_SYS (c32snrtombs, size_t, + (char *dest, const char32_t **srcp, size_t srclen, size_t len, + mbstate_t *ps)); +_GL_CXXALIASWARN (c32snrtombs); +#endif + + +/* Convert a 32-bit wide string to a string. */ #if @GNULIB_C32SRTOMBS@ _GL_FUNCDECL_SYS (c32srtombs, size_t, (char *dest, const char32_t **srcp, size_t len, mbstate_t *ps) diff --git a/lib/wcsnrtombs-impl.h b/lib/wcsnrtombs-impl.h index b50c6c0..7af3b36 100644 --- a/lib/wcsnrtombs-impl.h +++ b/lib/wcsnrtombs-impl.h @@ -16,12 +16,12 @@ along with this program. If not, see . */ size_t -wcsnrtombs (char *dest, const wchar_t **srcp, size_t srclen, size_t len, mbstate_t *ps) +FUNC (char *dest, const SCHAR_T **srcp, size_t srclen, size_t len, mbstate_t *ps) { if (ps == NULL) - ps = &_gl_wcsrtombs_state; + ps = &INTERNAL_STATE; { - const wchar_t *src = *srcp; + const SCHAR_T *src = *srcp; size_t cur_max = MB_CUR_MAX; char buf[64]; @@ -34,8 +34,8 @@ wcsnrtombs (char *dest, const wchar_t **srcp, size_t srclen, size_t len, mbstate for (; srclen > 0 && len > 0; src++, srclen--) { - wchar_t wc = *src; - size_t ret = wcrtomb (len >= cur_max ? destptr : buf, wc, ps); + SCHAR_T wc = *src; + size_t ret = WCRTOMB (len >= cur_max ? destptr : buf, wc, ps); if (ret == (size_t)(-1)) goto bad_input; @@ -66,8 +66,8 @@ wcsnrtombs (char *dest, const wchar_t **srcp, size_t srclen, size_t len, mbstate for (; srclen > 0; src++, srclen--) { - wchar_t wc = *src; - size_t ret = wcrtomb (buf, wc, &state); + SCHAR_T wc = *src; + size_t ret = WCRTOMB (buf, wc, &state); if (ret == (size_t)(-1)) goto bad_input2; diff --git a/lib/wcsnrtombs.c b/lib/wcsnrtombs.c index 236bfc7..88be656 100644 --- a/lib/wcsnrtombs.c +++ b/lib/wcsnrtombs.c @@ -27,4 +27,8 @@ extern mbstate_t _gl_wcsrtombs_state; +#define FUNC wcsnrtombs +#define SCHAR_T wchar_t +#define INTERNAL_STATE _gl_wcsrtombs_state +#define WCRTOMB wcrtomb #include "wcsnrtombs-impl.h" diff --git a/m4/uchar.m4 b/m4/uchar.m4 index 4e9b16d..2a84bd1 100644 --- a/m4/uchar.m4 +++ b/m4/uchar.m4 @@ -1,4 +1,4 @@ -# uchar.m4 serial 10 +# uchar.m4 serial 11 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, @@ -49,6 +49,7 @@ AC_DEFUN([gl_UCHAR_H_DEFAULTS], [ GNULIB_BTOC32=0; AC_SUBST([GNULIB_BTOC32]) GNULIB_C32RTOMB=0; AC_SUBST([GNULIB_C32RTOMB]) + GNULIB_C32SNRTOMBS=0; AC_SUBST([GNULIB_C32SNRTOMBS]) GNULIB_C32SRTOMBS=0; AC_SUBST([GNULIB_C32SRTOMBS]) GNULIB_C32TOB=0; AC_SUBST([GNULIB_C32TOB]) GNULIB_MBRTOC32=0; AC_SUBST([GNULIB_MBRTOC32]) diff --git a/modules/c32snrtombs b/modules/c32snrtombs new file mode 100644 index 0000000..4ced9f2 --- /dev/null +++ b/modules/c32snrtombs @@ -0,0 +1,31 @@ +Description: +c32snrtombs() function: convert 32-bit wide string to string. + +Files: +lib/c32snrtombs.c +lib/wcsnrtombs-impl.h +lib/c32srtombs-state.c + +Depends-on: +uchar +wchar +verify +c32rtomb +wcsnrtombs [test $SMALL_WCHAR_T = 0] + +configure.ac: +AC_REQUIRE([gl_UCHAR_H]) +AC_LIBOBJ([c32srtombs-state]) +gl_UCHAR_MODULE_INDICATOR([c32snrtombs]) + +Makefile.am: +lib_SOURCES += c32snrtombs.c + +Include: + + +License: +LGPL + +Maintainer: +Bruno Haible diff --git a/modules/uchar b/modules/uchar index 7124a67..c7e86ed 100644 --- a/modules/uchar +++ b/modules/uchar @@ -30,6 +30,7 @@ uchar.h: uchar.in.h $(top_builddir)/config.status $(CXXDEFS_H) -e 's|@''SMALL_WCHAR_T''@|$(SMALL_WCHAR_T)|g' \ -e 's/@''GNULIB_BTOC32''@/$(GNULIB_BTOC32)/g' \ -e 's/@''GNULIB_C32RTOMB''@/$(GNULIB_C32RTOMB)/g' \ + -e 's/@''GNULIB_C32SNRTOMBS''@/$(GNULIB_C32SNRTOMBS)/g' \ -e 's/@''GNULIB_C32SRTOMBS''@/$(GNULIB_C32SRTOMBS)/g' \ -e 's/@''GNULIB_C32TOB''@/$(GNULIB_C32TOB)/g' \ -e 's/@''GNULIB_MBRTOC32''@/$(GNULIB_MBRTOC32)/g' \ diff --git a/tests/test-uchar-c++.cc b/tests/test-uchar-c++.cc index e202bbc..ae97d9c 100644 --- a/tests/test-uchar-c++.cc +++ b/tests/test-uchar-c++.cc @@ -33,6 +33,11 @@ SIGNATURE_CHECK (GNULIB_NAMESPACE::c32rtomb, size_t, (char *, char32_t , mbstate_t *)); #endif +#if GNULIB_TEST_C32SNRTOMBS +SIGNATURE_CHECK (GNULIB_NAMESPACE::c32snrtombs, size_t, + (char *, const char32_t **, size_t, size_t, mbstate_t *)); +#endif + #if GNULIB_TEST_C32SRTOMBS SIGNATURE_CHECK (GNULIB_NAMESPACE::c32srtombs, size_t, (char *, const char32_t **, size_t, mbstate_t *)); -- 2.7.4 --nextPart9309935.kGTjJD2t88 Content-Disposition: attachment; filename="0002-c32snrtombs-Add-tests.patch" Content-Transfer-Encoding: quoted-printable Content-Type: text/x-patch; charset="UTF-8"; name="0002-c32snrtombs-Add-tests.patch" =46rom e3fb76a5a384096363eb90881f52b8535ee5a7ce Mon Sep 17 00:00:00 2001 =46rom: Bruno Haible Date: Fri, 10 Jan 2020 23:29:57 +0100 Subject: [PATCH 2/2] c32snrtombs: Add tests. * tests/test-c32snrtombs.c: New file, based on tests/test-wcsnrtombs.c. * tests/test-c32snrtombs-1.sh: New file, based on tests/test-wcsnrtombs1.sh. * tests/test-c32snrtombs-2.sh: New file, based on tests/test-wcsnrtombs2.sh. * tests/test-c32snrtombs-3.sh: New file, based on tests/test-wcsnrtombs3.sh. * tests/test-c32snrtombs-4.sh: New file, based on tests/test-wcsnrtombs4.sh. * modules/c32snrtombs-tests: New file, based on modules/wcsnrtombs-tests. =2D-- ChangeLog | 13 +++ modules/c32snrtombs-tests | 32 +++++++ tests/test-c32snrtombs-1.sh | 15 ++++ tests/test-c32snrtombs-2.sh | 15 ++++ tests/test-c32snrtombs-3.sh | 15 ++++ tests/test-c32snrtombs-4.sh | 15 ++++ tests/test-c32snrtombs.c | 206 ++++++++++++++++++++++++++++++++++++++++= ++++ 7 files changed, 311 insertions(+) create mode 100644 modules/c32snrtombs-tests create mode 100755 tests/test-c32snrtombs-1.sh create mode 100755 tests/test-c32snrtombs-2.sh create mode 100755 tests/test-c32snrtombs-3.sh create mode 100755 tests/test-c32snrtombs-4.sh create mode 100644 tests/test-c32snrtombs.c diff --git a/ChangeLog b/ChangeLog index 84bc7d2..e523162 100644 =2D-- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,18 @@ 2020-01-10 Bruno Haible =20 + c32snrtombs: Add tests. + * tests/test-c32snrtombs.c: New file, based on tests/test-wcsnrtombs.c. + * tests/test-c32snrtombs-1.sh: New file, based on + tests/test-wcsnrtombs1.sh. + * tests/test-c32snrtombs-2.sh: New file, based on + tests/test-wcsnrtombs2.sh. + * tests/test-c32snrtombs-3.sh: New file, based on + tests/test-wcsnrtombs3.sh. + * tests/test-c32snrtombs-4.sh: New file, based on + tests/test-wcsnrtombs4.sh. + * modules/c32snrtombs-tests: New file, based on + modules/wcsnrtombs-tests. + c32snrtombs: New module. * lib/uchar.in.h (c32snrtombs): New declaration. * lib/wcsnrtombs-impl.h: Parameterize: Use macros FUNC, SCHAR_T, diff --git a/modules/c32snrtombs-tests b/modules/c32snrtombs-tests new file mode 100644 index 0000000..038d334 =2D-- /dev/null +++ b/modules/c32snrtombs-tests @@ -0,0 +1,32 @@ +Files: +tests/test-c32snrtombs-1.sh +tests/test-c32snrtombs-2.sh +tests/test-c32snrtombs-3.sh +tests/test-c32snrtombs-4.sh +tests/test-c32snrtombs.c +tests/signature.h +tests/macros.h +m4/locale-fr.m4 +m4/locale-ja.m4 +m4/locale-zh.m4 +m4/codeset.m4 + +Depends-on: +setlocale +mbstoc32s + +configure.ac: +gt_LOCALE_FR +gt_LOCALE_FR_UTF8 +gt_LOCALE_JA +gt_LOCALE_ZH_CN + +Makefile.am: +TESTS +=3D test-c32snrtombs-1.sh test-c32snrtombs-2.sh test-c32snrtombs-3.= sh test-c32snrtombs-4.sh +TESTS_ENVIRONMENT +=3D \ + LOCALE_FR=3D'@LOCALE_FR@' \ + LOCALE_FR_UTF8=3D'@LOCALE_FR_UTF8@' \ + LOCALE_JA=3D'@LOCALE_JA@' \ + LOCALE_ZH_CN=3D'@LOCALE_ZH_CN@' +check_PROGRAMS +=3D test-c32snrtombs +test_c32snrtombs_LDADD =3D $(LDADD) $(LIB_SETLOCALE) diff --git a/tests/test-c32snrtombs-1.sh b/tests/test-c32snrtombs-1.sh new file mode 100755 index 0000000..608c6d1 =2D-- /dev/null +++ b/tests/test-c32snrtombs-1.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +# Test in an ISO-8859-1 or ISO-8859-15 locale. +: ${LOCALE_FR=3Dfr_FR} +if test $LOCALE_FR =3D none; then + if test -f /usr/bin/localedef; then + echo "Skipping test: no traditional french locale is installed" + else + echo "Skipping test: no traditional french locale is supported" + fi + exit 77 +fi + +LC_ALL=3D$LOCALE_FR \ +${CHECKER} ./test-c32snrtombs${EXEEXT} 1 diff --git a/tests/test-c32snrtombs-2.sh b/tests/test-c32snrtombs-2.sh new file mode 100755 index 0000000..5b437f1 =2D-- /dev/null +++ b/tests/test-c32snrtombs-2.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +# Test whether a specific UTF-8 locale is installed. +: ${LOCALE_FR_UTF8=3Dfr_FR.UTF-8} +if test $LOCALE_FR_UTF8 =3D none; then + if test -f /usr/bin/localedef; then + echo "Skipping test: no french Unicode locale is installed" + else + echo "Skipping test: no french Unicode locale is supported" + fi + exit 77 +fi + +LC_ALL=3D$LOCALE_FR_UTF8 \ +${CHECKER} ./test-c32snrtombs${EXEEXT} 2 diff --git a/tests/test-c32snrtombs-3.sh b/tests/test-c32snrtombs-3.sh new file mode 100755 index 0000000..bd77bf4 =2D-- /dev/null +++ b/tests/test-c32snrtombs-3.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +# Test whether a specific EUC-JP locale is installed. +: ${LOCALE_JA=3Dja_JP} +if test $LOCALE_JA =3D none; then + if test -f /usr/bin/localedef; then + echo "Skipping test: no traditional japanese locale is installed" + else + echo "Skipping test: no traditional japanese locale is supported" + fi + exit 77 +fi + +LC_ALL=3D$LOCALE_JA \ +${CHECKER} ./test-c32snrtombs${EXEEXT} 3 diff --git a/tests/test-c32snrtombs-4.sh b/tests/test-c32snrtombs-4.sh new file mode 100755 index 0000000..3332297 =2D-- /dev/null +++ b/tests/test-c32snrtombs-4.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +# Test whether a specific GB18030 locale is installed. +: ${LOCALE_ZH_CN=3Dzh_CN.GB18030} +if test $LOCALE_ZH_CN =3D none; then + if test -f /usr/bin/localedef; then + echo "Skipping test: no transitional chinese locale is installed" + else + echo "Skipping test: no transitional chinese locale is supported" + fi + exit 77 +fi + +LC_ALL=3D$LOCALE_ZH_CN \ +${CHECKER} ./test-c32snrtombs${EXEEXT} 4 diff --git a/tests/test-c32snrtombs.c b/tests/test-c32snrtombs.c new file mode 100644 index 0000000..dcf4f55 =2D-- /dev/null +++ b/tests/test-c32snrtombs.c @@ -0,0 +1,206 @@ +/* Test of conversion of 32-bit wide string to string. + Copyright (C) 2008-2020 Free Software Foundation, Inc. + + 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 . = */ + +/* Written by Bruno Haible , 2008. */ + +#include + +#include + +#include "signature.h" +SIGNATURE_CHECK (c32snrtombs, size_t, + (char *, const char32_t **, size_t, size_t, mbstate_t *)); + +#include +#include +#include + +#include "macros.h" + +int +main (int argc, char *argv[]) +{ + /* configure should already have checked that the locale is supported. = */ + if (setlocale (LC_ALL, "") =3D=3D NULL) + return 1; + + if (argc > 1) + { + char32_t input[10]; + size_t n; + const char32_t *src; + #define BUFSIZE 20 + char buf[BUFSIZE]; + size_t ret; + + { + size_t i; + for (i =3D 0; i < BUFSIZE; i++) + buf[i] =3D '_'; + } + + switch (argv[1][0]) + { + case '1': + /* Locale encoding is ISO-8859-1 or ISO-8859-15. */ + { + const char original[] =3D "B\374\337er"; /* "B=C3=BC=C3=9Fer" = */ + + ret =3D mbstoc32s (input, original, 10); + ASSERT (ret =3D=3D 5); + + for (n =3D 0; n < 10; n++) + { + src =3D input; + ret =3D c32snrtombs (NULL, &src, 6, n, NULL); + ASSERT (ret =3D=3D 5); + ASSERT (src =3D=3D input); + + src =3D input; + ret =3D c32snrtombs (buf, &src, 6, n, NULL); + ASSERT (ret =3D=3D (n <=3D 5 ? n : 5)); + ASSERT (src =3D=3D (n <=3D 5 ? input + n : NULL)); + ASSERT (memcmp (buf, original, ret) =3D=3D 0); + if (src =3D=3D NULL) + ASSERT (buf[ret] =3D=3D '\0'); + ASSERT (buf[ret + (src =3D=3D NULL) + 0] =3D=3D '_'); + ASSERT (buf[ret + (src =3D=3D NULL) + 1] =3D=3D '_'); + ASSERT (buf[ret + (src =3D=3D NULL) + 2] =3D=3D '_'); + } + } + break; + + case '2': + /* Locale encoding is UTF-8. */ + { + const char original[] =3D "s\303\274\303\237\360\237\230\213!"= ; /* "s=C3=BC=C3=9F=F0=9F=98=8B!" */ + + ret =3D mbstoc32s (input, original, 10); + ASSERT (ret =3D=3D 5); + + for (n =3D 0; n < 15; n++) + { + src =3D input; + ret =3D c32snrtombs (NULL, &src, 6, n, NULL); + ASSERT (ret =3D=3D 10); + ASSERT (src =3D=3D input); + + src =3D input; + ret =3D c32snrtombs (buf, &src, 6, n, NULL); + ASSERT (ret =3D=3D (n < 1 ? n : + n < 3 ? 1 : + n < 5 ? 3 : + n < 9 ? 5 : + n <=3D 10 ? n : 10)); + ASSERT (src =3D=3D (n < 1 ? input + n : + n < 3 ? input + 1 : + n < 5 ? input + 2 : + n < 9 ? input + 3 : + n <=3D 10 ? input + (n - 5) : NULL)); + ASSERT (memcmp (buf, original, ret) =3D=3D 0); + if (src =3D=3D NULL) + ASSERT (buf[ret] =3D=3D '\0'); + ASSERT (buf[ret + (src =3D=3D NULL) + 0] =3D=3D '_'); + ASSERT (buf[ret + (src =3D=3D NULL) + 1] =3D=3D '_'); + ASSERT (buf[ret + (src =3D=3D NULL) + 2] =3D=3D '_'); + } + } + break; + + case '3': + /* Locale encoding is EUC-JP. */ + { + const char original[] =3D "<\306\374\313\334\270\354>"; /* "<= =E6=97=A5=E6=9C=AC=E8=AA=9E>" */ + + ret =3D mbstoc32s (input, original, 10); + ASSERT (ret =3D=3D 5); + + for (n =3D 0; n < 10; n++) + { + src =3D input; + ret =3D c32snrtombs (NULL, &src, 6, n, NULL); + ASSERT (ret =3D=3D 8); + ASSERT (src =3D=3D input); + + src =3D input; + ret =3D c32snrtombs (buf, &src, 6, n, NULL); + ASSERT (ret =3D=3D (n < 1 ? n : + n < 3 ? 1 : + n < 5 ? 3 : + n < 7 ? 5 : + n <=3D 8 ? n : 8)); + ASSERT (src =3D=3D (n < 1 ? input + n : + n < 3 ? input + 1 : + n < 5 ? input + 2 : + n < 7 ? input + 3 : + n <=3D 8 ? input + (n - 3) : NULL)); + ASSERT (memcmp (buf, original, ret) =3D=3D 0); + if (src =3D=3D NULL) + ASSERT (buf[ret] =3D=3D '\0'); + ASSERT (buf[ret + (src =3D=3D NULL) + 0] =3D=3D '_'); + ASSERT (buf[ret + (src =3D=3D NULL) + 1] =3D=3D '_'); + ASSERT (buf[ret + (src =3D=3D NULL) + 2] =3D=3D '_'); + } + } + break; + + + case '4': + /* Locale encoding is GB18030. */ + { + const char original[] =3D "s\250\271\201\060\211\070\224\071\3= 75\067!"; /* "s=C3=BC=C3=9F=F0=9F=98=8B!" */ + + ret =3D mbstoc32s (input, original, 10); + ASSERT (ret =3D=3D 5); + + for (n =3D 0; n < 15; n++) + { + src =3D input; + ret =3D c32snrtombs (NULL, &src, 6, n, NULL); + ASSERT (ret =3D=3D 12); + ASSERT (src =3D=3D input); + + src =3D input; + ret =3D c32snrtombs (buf, &src, 6, n, NULL); + ASSERT (ret =3D=3D (n < 1 ? n : + n < 3 ? 1 : + n < 7 ? 3 : + n < 11 ? 7 : + n <=3D 12 ? n : 12)); + ASSERT (src =3D=3D (n < 1 ? input + n : + n < 3 ? input + 1 : + n < 7 ? input + 2 : + n < 11 ? input + 3 : + n <=3D 12 ? input + (n - 7) : NULL)); + ASSERT (memcmp (buf, original, ret) =3D=3D 0); + if (src =3D=3D NULL) + ASSERT (buf[ret] =3D=3D '\0'); + ASSERT (buf[ret + (src =3D=3D NULL) + 0] =3D=3D '_'); + ASSERT (buf[ret + (src =3D=3D NULL) + 1] =3D=3D '_'); + ASSERT (buf[ret + (src =3D=3D NULL) + 2] =3D=3D '_'); + } + } + break; + + default: + return 1; + } + + return 0; + } + + return 1; +} =2D-=20 2.7.4 --nextPart9309935.kGTjJD2t88--