From: Bruno Haible Date: Sun, 16 Feb 2025 12:02:25 +0000 (+0100) Subject: c-strcasecmp, c-strncasecmp: New modules. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f656293f0e76f95fd77fbae7c1d356e6449d5d90;p=thirdparty%2Fgnulib.git c-strcasecmp, c-strncasecmp: New modules. * modules/c-strcasecmp: New file. * modules/c-strncasecmp: New file. * modules/c-strcase: Merely depend on c-strcasecmp, c-strncasecmp. * lib/strings.in.h (strcasecmp, strncasecmp): Update warning message. * tests/test-c-strcasecmp.sh: New file, based on tests/test-c-strcase.sh. * tests/test-c-strncasecmp.sh: New file, based on tests/test-c-strcase.sh. * tests/test-c-strcase.sh: Remove file. * modules/c-strcasecmp-tests: New file. * modules/c-strncasecmp-tests: New file. * modules/c-strcase-tests: Remove file. * doc/c-strcasecmp.texi: New file, based on doc/c-strcase.texi. * doc/c-strncasecmp.texi: New file, based on doc/c-strcase.texi. * doc/c-strcase.texi: Remove file. * doc/c-locale.texi: Include c-strcasecmp.texi and c-strncasecmp.texi separately. * modules/c-strcaseeq (Depends-on): Add c-strcasecmp. Remove c-strcase. * modules/iconv_open (Depends-on): Likewise. * modules/nl_langinfo-tests (Depends-on): Likewise. * modules/propername (Depends-on): Likewise. * modules/propername-lite (Depends-on): Likewise. * modules/striconv (Depends-on): Likewise. * modules/striconveh (Depends-on): Likewise. * modules/striconveha (Depends-on): Likewise. * modules/c-strcasestr (Depends-on): Add c-strncasecmp. Remove c-strcase. --- diff --git a/ChangeLog b/ChangeLog index 65b34ef3fc..5829c3bd9e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,34 @@ +2025-02-16 Bruno Haible + + c-strcasecmp, c-strncasecmp: New modules. + * modules/c-strcasecmp: New file. + * modules/c-strncasecmp: New file. + * modules/c-strcase: Merely depend on c-strcasecmp, c-strncasecmp. + * lib/strings.in.h (strcasecmp, strncasecmp): Update warning message. + * tests/test-c-strcasecmp.sh: New file, based on + tests/test-c-strcase.sh. + * tests/test-c-strncasecmp.sh: New file, based on + tests/test-c-strcase.sh. + * tests/test-c-strcase.sh: Remove file. + * modules/c-strcasecmp-tests: New file. + * modules/c-strncasecmp-tests: New file. + * modules/c-strcase-tests: Remove file. + * doc/c-strcasecmp.texi: New file, based on doc/c-strcase.texi. + * doc/c-strncasecmp.texi: New file, based on doc/c-strcase.texi. + * doc/c-strcase.texi: Remove file. + * doc/c-locale.texi: Include c-strcasecmp.texi and c-strncasecmp.texi + separately. + * modules/c-strcaseeq (Depends-on): Add c-strcasecmp. Remove c-strcase. + * modules/iconv_open (Depends-on): Likewise. + * modules/nl_langinfo-tests (Depends-on): Likewise. + * modules/propername (Depends-on): Likewise. + * modules/propername-lite (Depends-on): Likewise. + * modules/striconv (Depends-on): Likewise. + * modules/striconveh (Depends-on): Likewise. + * modules/striconveha (Depends-on): Likewise. + * modules/c-strcasestr (Depends-on): Add c-strncasecmp. Remove + c-strcase. + 2025-02-16 Bruno Haible strings-h: Don't declare strcasecmp, strncasecmp without the module. diff --git a/doc/c-locale.texi b/doc/c-locale.texi index b9f6274873..41b17a3980 100644 --- a/doc/c-locale.texi +++ b/doc/c-locale.texi @@ -16,8 +16,9 @@ The functions are provided by the following modules. @menu * c-ctype:: -* c-strcase:: * c-strcaseeq:: +* c-strcasecmp:: +* c-strncasecmp:: * c-strcasestr:: * c-strstr:: * c-strtod:: @@ -28,14 +29,18 @@ The functions are provided by the following modules. @subsubsection c-ctype @include c-ctype.texi -@node c-strcase -@subsubsection c-strcase -@include c-strcase.texi - @node c-strcaseeq @subsubsection c-strcaseeq @include c-strcaseeq.texi +@node c-strcasecmp +@subsubsection c-strcasecmp +@include c-strcasecmp.texi + +@node c-strncasecmp +@subsubsection c-strncasecmp +@include c-strncasecmp.texi + @node c-strcasestr @subsubsection c-strcasestr @include c-strcasestr.texi diff --git a/doc/c-strcasecmp.texi b/doc/c-strcasecmp.texi new file mode 100644 index 0000000000..971d021707 --- /dev/null +++ b/doc/c-strcasecmp.texi @@ -0,0 +1,29 @@ +@c Documentation of gnulib module 'c-strcasecmp'. + +@c Copyright (C) 2008--2025 Free Software Foundation, Inc. + +@c Permission is granted to copy, distribute and/or modify this document +@c under the terms of the GNU Free Documentation License, Version 1.3 or +@c any later version published by the Free Software Foundation; with no +@c Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A +@c copy of the license is at . + +@mindex c-strcasecmp +The @code{c-strcasecmp} module contains a case-insensitive string comparison +function operating on single-byte character strings, like the functions in +@code{}, that operate as if the locale encoding was ASCII. +(The "C" locale on many systems has the locale encoding "ASCII".) + +The function is: +@smallexample +extern int c_strcasecmp (const char *s1, const char *s2); +@end smallexample + +For case conversion here, only ASCII characters are considered to be +upper case or lower case. + +Note: The function @code{strcasecmp} from @code{} +supports only unibyte locales; +@mindex mbscasecmp +for multibyte locales, +you need the function @code{mbscasecmp}. diff --git a/doc/c-strcase.texi b/doc/c-strncasecmp.texi similarity index 62% rename from doc/c-strcase.texi rename to doc/c-strncasecmp.texi index 5c31fecc36..61ed3d5ae0 100644 --- a/doc/c-strcase.texi +++ b/doc/c-strncasecmp.texi @@ -1,4 +1,4 @@ -@c Documentation of gnulib module 'c-strcase'. +@c Documentation of gnulib module 'c-strncasecmp'. @c Copyright (C) 2008--2025 Free Software Foundation, Inc. @@ -8,26 +8,23 @@ @c Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A @c copy of the license is at . -@mindex c-strcase -The @code{c-strcase} module contains case-insensitive string comparison -functions operating on single-byte character strings, like the functions in +@mindex c-strncasecmp +The @code{c-strncasecmp} module contains a case-insensitive string comparison +function operating on single-byte character strings, like the functions in @code{}, that operate as if the locale encoding was ASCII. (The "C" locale on many systems has the locale encoding "ASCII".) -The functions are: +The function is: @smallexample -extern int c_strcasecmp (const char *s1, const char *s2); extern int c_strncasecmp (const char *s1, const char *s2, size_t n); @end smallexample For case conversion here, only ASCII characters are considered to be upper case or lower case. -Note: The functions @code{strcasecmp}, @code{strncasecmp} from -@code{} support only unibyte locales; -@mindex mbscasecmp +Note: The function @code{strncasecmp} from @code{} +supports only unibyte locales; @mindex mbsncasecmp @mindex mbspcasecmp for multibyte locales, -you need the functions @code{mbscasecmp}, @code{mbsncasecmp}, -@code{mbspcasecmp}. +you need the function @code{mbsncasecmp} or @code{mbspcasecmp}. diff --git a/lib/strings.in.h b/lib/strings.in.h index d7bd1ae917..cad01dc34b 100644 --- a/lib/strings.in.h +++ b/lib/strings.in.h @@ -91,7 +91,7 @@ _GL_WARN_ON_USE (strcasecmp, "strcasecmp cannot work correctly on character " "strings in multibyte locales - " "use mbscasecmp if you care about " "internationalization, or use c_strcasecmp " - "(gnulib module c-strcase) if you want a locale " + "(gnulib module c-strcasecmp) if you want a locale " "independent function"); # endif #endif @@ -115,7 +115,7 @@ _GL_WARN_ON_USE (strncasecmp, "strncasecmp cannot work correctly on character " "strings in multibyte locales - " "use mbsncasecmp or mbspcasecmp if you care about " "internationalization, or use c_strncasecmp " - "(gnulib module c-strcase) if you want a locale " + "(gnulib module c-strncasecmp) if you want a locale " "independent function"); # endif #endif diff --git a/modules/c-strcase b/modules/c-strcase index 1af2c8ee9e..10fc5a5ab3 100644 --- a/modules/c-strcase +++ b/modules/c-strcase @@ -2,17 +2,14 @@ Description: Case-insensitive string comparison functions in C locale. Files: -lib/c-strcase.h -lib/c-strcasecmp.c -lib/c-strncasecmp.c Depends-on: -c-ctype +c-strcasecmp +c-strncasecmp configure.ac: Makefile.am: -lib_SOURCES += c-strcase.h c-strcasecmp.c c-strncasecmp.c Include: "c-strcase.h" diff --git a/modules/c-strcasecmp b/modules/c-strcasecmp new file mode 100644 index 0000000000..d9afa54213 --- /dev/null +++ b/modules/c-strcasecmp @@ -0,0 +1,23 @@ +Description: +Case-insensitive string comparison functions in C locale. + +Files: +lib/c-strcase.h +lib/c-strcasecmp.c + +Depends-on: +c-ctype + +configure.ac: + +Makefile.am: +lib_SOURCES += c-strcasecmp.c + +Include: +"c-strcase.h" + +License: +LGPLv2+ + +Maintainer: +all diff --git a/modules/c-strcasecmp-tests b/modules/c-strcasecmp-tests new file mode 100644 index 0000000000..6f5b0d2a0e --- /dev/null +++ b/modules/c-strcasecmp-tests @@ -0,0 +1,21 @@ +Files: +tests/test-c-strcasecmp.sh +tests/test-c-strcasecmp.c +tests/macros.h +m4/locale-fr.m4 +m4/locale-tr.m4 +m4/codeset.m4 + +Depends-on: +c-ctype +setlocale + +configure.ac: +gt_LOCALE_FR +gt_LOCALE_TR_UTF8 + +Makefile.am: +TESTS += test-c-strcasecmp.sh +TESTS_ENVIRONMENT += LOCALE_FR='@LOCALE_FR@' LOCALE_TR_UTF8='@LOCALE_TR_UTF8@' +check_PROGRAMS += test-c-strcasecmp +test_c_strcasecmp_LDADD = $(LDADD) $(SETLOCALE_LIB) diff --git a/modules/c-strcaseeq b/modules/c-strcaseeq index 7569bc6697..90c3605805 100644 --- a/modules/c-strcaseeq +++ b/modules/c-strcaseeq @@ -5,7 +5,7 @@ Files: lib/c-strcaseeq.h Depends-on: -c-strcase +c-strcasecmp c-ctype configure.ac: diff --git a/modules/c-strcasestr b/modules/c-strcasestr index 0bc5a81b1b..3cc0b979b8 100644 --- a/modules/c-strcasestr +++ b/modules/c-strcasestr @@ -8,7 +8,7 @@ lib/str-two-way.h Depends-on: c-ctype -c-strcase +c-strncasecmp bool memchr memcmp diff --git a/modules/c-strncasecmp b/modules/c-strncasecmp new file mode 100644 index 0000000000..f2b0cf00f8 --- /dev/null +++ b/modules/c-strncasecmp @@ -0,0 +1,23 @@ +Description: +Case-insensitive string comparison functions in C locale. + +Files: +lib/c-strcase.h +lib/c-strncasecmp.c + +Depends-on: +c-ctype + +configure.ac: + +Makefile.am: +lib_SOURCES += c-strncasecmp.c + +Include: +"c-strcase.h" + +License: +LGPLv2+ + +Maintainer: +all diff --git a/modules/c-strcase-tests b/modules/c-strncasecmp-tests similarity index 63% rename from modules/c-strcase-tests rename to modules/c-strncasecmp-tests index 23a3eb8aba..7e7c94535f 100644 --- a/modules/c-strcase-tests +++ b/modules/c-strncasecmp-tests @@ -1,6 +1,5 @@ Files: -tests/test-c-strcase.sh -tests/test-c-strcasecmp.c +tests/test-c-strncasecmp.sh tests/test-c-strncasecmp.c tests/macros.h m4/locale-fr.m4 @@ -16,8 +15,7 @@ gt_LOCALE_FR gt_LOCALE_TR_UTF8 Makefile.am: -TESTS += test-c-strcase.sh +TESTS += test-c-strncasecmp.sh TESTS_ENVIRONMENT += LOCALE_FR='@LOCALE_FR@' LOCALE_TR_UTF8='@LOCALE_TR_UTF8@' -check_PROGRAMS += test-c-strcasecmp test-c-strncasecmp -test_c_strcasecmp_LDADD = $(LDADD) $(SETLOCALE_LIB) +check_PROGRAMS += test-c-strncasecmp test_c_strncasecmp_LDADD = $(LDADD) $(SETLOCALE_LIB) diff --git a/modules/iconv_open b/modules/iconv_open index 4993a07044..b3ed95c40f 100644 --- a/modules/iconv_open +++ b/modules/iconv_open @@ -18,7 +18,7 @@ gperf iconv-h iconv c-ctype [test $REPLACE_ICONV_OPEN = 1] -c-strcase [test $REPLACE_ICONV_OPEN = 1] +c-strcasecmp [test $REPLACE_ICONV_OPEN = 1] stdint-h [test $REPLACE_ICONV_UTF = 1] unistr/u8-mbtoucr [test $REPLACE_ICONV_UTF = 1] unistr/u8-uctomb [test $REPLACE_ICONV_UTF = 1] diff --git a/modules/nl_langinfo-tests b/modules/nl_langinfo-tests index 66bae5ffaf..a1125e290c 100644 --- a/modules/nl_langinfo-tests +++ b/modules/nl_langinfo-tests @@ -12,7 +12,7 @@ m4/intl-thread-locale.m4 m4/musl.m4 Depends-on: -c-strcase +c-strcasecmp c-strcasestr setlocale thread diff --git a/modules/propername b/modules/propername index 6e4ab3a4af..87de812dc8 100644 --- a/modules/propername +++ b/modules/propername @@ -14,7 +14,7 @@ mbchar mbuiter iconv localcharset -c-strcase +c-strcasecmp xstriconv xalloc gettext-h diff --git a/modules/propername-lite b/modules/propername-lite index 53f0187238..771ea21b61 100644 --- a/modules/propername-lite +++ b/modules/propername-lite @@ -7,7 +7,7 @@ lib/propername.h Depends-on: localcharset -c-strcase +c-strcasecmp gettext-h configure.ac: diff --git a/modules/striconv b/modules/striconv index 542287dcea..53b4b55ea5 100644 --- a/modules/striconv +++ b/modules/striconv @@ -10,7 +10,7 @@ iconv iconv_open free-posix strdup -c-strcase +c-strcasecmp configure.ac: if test $gl_cond_libtool = false; then diff --git a/modules/striconveh b/modules/striconveh index a55a26d7bf..ff746cc959 100644 --- a/modules/striconveh +++ b/modules/striconveh @@ -17,7 +17,7 @@ unistr/u8-mbtoucr unistr/u8-uctomb free-posix strdup -c-strcase +c-strcasecmp c-strcaseeq memmove diff --git a/modules/striconveha b/modules/striconveha index aa58691596..090855ccc9 100644 --- a/modules/striconveha +++ b/modules/striconveha @@ -11,7 +11,7 @@ bool striconveh malloca strdup -c-strcase +c-strcasecmp configure.ac: diff --git a/tests/test-c-strcasecmp.sh b/tests/test-c-strcasecmp.sh new file mode 100755 index 0000000000..8049c7b181 --- /dev/null +++ b/tests/test-c-strcasecmp.sh @@ -0,0 +1,18 @@ +#!/bin/sh + +# Test in the C locale. +${CHECKER} ./test-c-strcasecmp${EXEEXT} || exit 1 + +# Test in an ISO-8859-1 or ISO-8859-15 locale. +: "${LOCALE_FR=fr_FR}" +if test $LOCALE_FR != none; then + LC_ALL=$LOCALE_FR ${CHECKER} ./test-c-strcasecmp${EXEEXT} locale || exit 1 +fi + +# Test in a Turkish UTF-8 locale. +: "${LOCALE_TR_UTF8=tr_TR.UTF-8}" +if test $LOCALE_TR_UTF8 != none; then + LC_ALL=$LOCALE_TR_UTF8 ${CHECKER} ./test-c-strcasecmp${EXEEXT} locale || exit 1 +fi + +exit 0 diff --git a/tests/test-c-strcase.sh b/tests/test-c-strncasecmp.sh similarity index 69% rename from tests/test-c-strcase.sh rename to tests/test-c-strncasecmp.sh index 9f491e0f96..30067d153e 100755 --- a/tests/test-c-strcase.sh +++ b/tests/test-c-strncasecmp.sh @@ -1,20 +1,17 @@ #!/bin/sh # Test in the C locale. -${CHECKER} ./test-c-strcasecmp${EXEEXT} || exit 1 ${CHECKER} ./test-c-strncasecmp${EXEEXT} || exit 1 # Test in an ISO-8859-1 or ISO-8859-15 locale. : "${LOCALE_FR=fr_FR}" if test $LOCALE_FR != none; then - LC_ALL=$LOCALE_FR ${CHECKER} ./test-c-strcasecmp${EXEEXT} locale || exit 1 LC_ALL=$LOCALE_FR ${CHECKER} ./test-c-strncasecmp${EXEEXT} locale || exit 1 fi # Test in a Turkish UTF-8 locale. : "${LOCALE_TR_UTF8=tr_TR.UTF-8}" if test $LOCALE_TR_UTF8 != none; then - LC_ALL=$LOCALE_TR_UTF8 ${CHECKER} ./test-c-strcasecmp${EXEEXT} locale || exit 1 LC_ALL=$LOCALE_TR_UTF8 ${CHECKER} ./test-c-strncasecmp${EXEEXT} locale || exit 1 fi