The functions strcasecmp, strncasecmp are provided by a single module: 'strcase'.
Similarly, the functions c_strcasecmp, c_strncasecmp are provided by a single module: 'c-strcase'. While this saves a little bit of module description and *.m4 code, it has two drawbacks: - It blurs the usual correspondence of 1 function = 1 module. - It causes 2 compilation units to be compiled even when only one of them is needed. These patches straighten the situation, by creating a new module for each of these functions. Of course, the modules 'strcase' and 'c-strcase' remain functional, for backward compatibility. 2025-02-16 Bruno Haible <br...@clisp.org> 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 <br...@clisp.org> strings-h: Don't declare strcasecmp, strncasecmp without the module. * lib/strings.in.h (strcasecmp): Don't declare if module 'strcasecmp' is not present. (strncasecmp): Don't declare if module 'strncasecmp' is not present. * m4/strings_h.m4 (gl_STRINGS_H_REQUIRE_DEFAULTS): Initialize GNULIB_STRCASECMP, GNULIB_STRNCASECMP. * modules/strings-h (Makefile.am): Substitute GNULIB_STRCASECMP, GNULIB_STRNCASECMP. 2025-02-16 Bruno Haible <br...@clisp.org> strcasecmp, strncasecmp: New modules. * modules/strcasecmp: New file. * modules/strncasecmp: New file. * modules/strcase: Merely depend on strcasecmp, strncasecmp. * m4/strcasecmp.m4: New file, based on m4/strcase.m4. * m4/strncasecmp.m4: New file, based on m4/strcase.m4. * m4/strcase.m4: Remove file. * lib/strings.in.h (strcasecmp, strncasecmp): Fix typo in warning message. * lib/strcasecmp.c: Improve comment. * lib/strncasecmp.c: Likewise. * doc/posix-functions/strcasecmp.texi: Mention module strcasecmp, not module strcase. * doc/posix-functions/strncasecmp.texi: Mention module strncasecmp, not module strcase. * doc/strings.texi (Comparison of string APIs): Reference modules strcasecmp, strncasecmp. * modules/argp (Depends-on): Add strcasecmp. Remove strcase. * modules/strcasestr-simple (Depends-on): Add strncasecmp. Remove strcase. * modules/strptime (Depends-on): Likewise.
>From b2927d1b1fa3fb09a2210a3df5691f7d48d6151b Mon Sep 17 00:00:00 2001 From: Bruno Haible <br...@clisp.org> Date: Sun, 16 Feb 2025 12:21:53 +0100 Subject: [PATCH 1/3] strcasecmp, strncasecmp: New modules. * modules/strcasecmp: New file. * modules/strncasecmp: New file. * modules/strcase: Merely depend on strcasecmp, strncasecmp. * m4/strcasecmp.m4: New file, based on m4/strcase.m4. * m4/strncasecmp.m4: New file, based on m4/strcase.m4. * m4/strcase.m4: Remove file. * lib/strings.in.h (strcasecmp, strncasecmp): Fix typo in warning message. * lib/strcasecmp.c: Improve comment. * lib/strncasecmp.c: Likewise. * doc/posix-functions/strcasecmp.texi: Mention module strcasecmp, not module strcase. * doc/posix-functions/strncasecmp.texi: Mention module strncasecmp, not module strcase. * doc/strings.texi (Comparison of string APIs): Reference modules strcasecmp, strncasecmp. * modules/argp (Depends-on): Add strcasecmp. Remove strcase. * modules/strcasestr-simple (Depends-on): Add strncasecmp. Remove strcase. * modules/strptime (Depends-on): Likewise. --- ChangeLog | 24 ++++++++++++++++++++++ doc/posix-functions/strcasecmp.texi | 4 ++-- doc/posix-functions/strncasecmp.texi | 4 ++-- doc/strings.texi | 3 ++- lib/strcasecmp.c | 2 +- lib/strings.in.h | 8 ++++---- lib/strncasecmp.c | 2 +- m4/strcasecmp.m4 | 21 +++++++++++++++++++ m4/{strcase.m4 => strncasecmp.m4} | 26 +++--------------------- modules/argp | 2 +- modules/strcase | 23 +++------------------ modules/strcasecmp | 30 ++++++++++++++++++++++++++++ modules/strcasestr-simple | 2 +- modules/strncasecmp | 30 ++++++++++++++++++++++++++++ modules/strptime | 2 +- 15 files changed, 126 insertions(+), 57 deletions(-) create mode 100644 m4/strcasecmp.m4 rename m4/{strcase.m4 => strncasecmp.m4} (61%) create mode 100644 modules/strcasecmp create mode 100644 modules/strncasecmp diff --git a/ChangeLog b/ChangeLog index 53bb437073..37255b17ea 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,27 @@ +2025-02-16 Bruno Haible <br...@clisp.org> + + strcasecmp, strncasecmp: New modules. + * modules/strcasecmp: New file. + * modules/strncasecmp: New file. + * modules/strcase: Merely depend on strcasecmp, strncasecmp. + * m4/strcasecmp.m4: New file, based on m4/strcase.m4. + * m4/strncasecmp.m4: New file, based on m4/strcase.m4. + * m4/strcase.m4: Remove file. + * lib/strings.in.h (strcasecmp, strncasecmp): Fix typo in warning + message. + * lib/strcasecmp.c: Improve comment. + * lib/strncasecmp.c: Likewise. + * doc/posix-functions/strcasecmp.texi: Mention module strcasecmp, not + module strcase. + * doc/posix-functions/strncasecmp.texi: Mention module strncasecmp, not + module strcase. + * doc/strings.texi (Comparison of string APIs): Reference modules + strcasecmp, strncasecmp. + * modules/argp (Depends-on): Add strcasecmp. Remove strcase. + * modules/strcasestr-simple (Depends-on): Add strncasecmp. Remove + strcase. + * modules/strptime (Depends-on): Likewise. + 2025-02-16 Bruno Haible <br...@clisp.org> ctype-h: Make ctype.h self-contained again (regr. 2025-02-14). diff --git a/doc/posix-functions/strcasecmp.texi b/doc/posix-functions/strcasecmp.texi index 2de26616b2..af640589d9 100644 --- a/doc/posix-functions/strcasecmp.texi +++ b/doc/posix-functions/strcasecmp.texi @@ -4,8 +4,8 @@ POSIX specification:@* @url{https://pubs.opengroup.org/onlinepubs/9799919799/functions/strcasecmp.html} -Gnulib module: strcase -@mindex strcase +Gnulib module: strcasecmp +@mindex strcasecmp Portability problems fixed by Gnulib: @itemize diff --git a/doc/posix-functions/strncasecmp.texi b/doc/posix-functions/strncasecmp.texi index 5273870215..1fc9e0307a 100644 --- a/doc/posix-functions/strncasecmp.texi +++ b/doc/posix-functions/strncasecmp.texi @@ -4,8 +4,8 @@ POSIX specification:@* @url{https://pubs.opengroup.org/onlinepubs/9799919799/functions/strncasecmp.html} -Gnulib module: strcase -@mindex strcase +Gnulib module: strncasecmp +@mindex strncasecmp Portability problems fixed by Gnulib: @itemize diff --git a/doc/strings.texi b/doc/strings.texi index 0493233ba0..a33067f1f8 100644 --- a/doc/strings.texi +++ b/doc/strings.texi @@ -324,11 +324,12 @@ @mindex mbs_startswith @mindex stpcpy @mindex stpncpy -@mindex strcase +@mindex strcasecmp @mindex strcasestr @mindex strcspn @mindex strdup @mindex string-desc +@mindex strncasecmp @mindex strncat @mindex strndup @mindex strnlen diff --git a/lib/strcasecmp.c b/lib/strcasecmp.c index 27329368ad..fe21a6d5b3 100644 --- a/lib/strcasecmp.c +++ b/lib/strcasecmp.c @@ -1,4 +1,4 @@ -/* Case-insensitive string comparison function. +/* Case-insensitive string comparison function for unibyte locales. Copyright (C) 1998-1999, 2005-2007, 2009-2025 Free Software Foundation, Inc. This file is free software: you can redistribute it and/or modify diff --git a/lib/strings.in.h b/lib/strings.in.h index b09f3eed89..f99b7c95e8 100644 --- a/lib/strings.in.h +++ b/lib/strings.in.h @@ -89,8 +89,8 @@ extern int strcasecmp (char const *s1, char const *s2) _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 " + "internationalization, or use c_strcasecmp " + "(gnulib module c-strcase) if you want a locale " "independent function"); # endif #endif @@ -112,8 +112,8 @@ extern int strncasecmp (char const *s1, char const *s2, size_t n) _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 " + "internationalization, or use c_strncasecmp " + "(gnulib module c-strcase) if you want a locale " "independent function"); # endif #endif diff --git a/lib/strncasecmp.c b/lib/strncasecmp.c index 815843859a..7a0115d050 100644 --- a/lib/strncasecmp.c +++ b/lib/strncasecmp.c @@ -1,4 +1,4 @@ -/* strncasecmp.c -- case insensitive string comparator +/* Case-insensitive string comparison function for unibyte locales. Copyright (C) 1998-1999, 2005-2007, 2009-2025 Free Software Foundation, Inc. This file is free software: you can redistribute it and/or modify diff --git a/m4/strcasecmp.m4 b/m4/strcasecmp.m4 new file mode 100644 index 0000000000..0bbcc5ebe2 --- /dev/null +++ b/m4/strcasecmp.m4 @@ -0,0 +1,21 @@ +# strcasecmp.m4 +# serial 1 +dnl Copyright (C) 2002-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_STRCASECMP], +[ + AC_REQUIRE([gl_STRINGS_H_DEFAULTS]) + AC_CHECK_FUNCS([strcasecmp]) + if test $ac_cv_func_strcasecmp = no; then + HAVE_STRCASECMP=0 + fi +]) + +# Prerequisites of lib/strcasecmp.c. +AC_DEFUN([gl_PREREQ_STRCASECMP], [ + : +]) diff --git a/m4/strcase.m4 b/m4/strncasecmp.m4 similarity index 61% rename from m4/strcase.m4 rename to m4/strncasecmp.m4 index ecb2c91c8b..d27a4a0c5e 100644 --- a/m4/strcase.m4 +++ b/m4/strncasecmp.m4 @@ -1,26 +1,11 @@ -# strcase.m4 -# serial 12 -dnl Copyright (C) 2002, 2005-2025 Free Software Foundation, Inc. +# strncasecmp.m4 +# serial 1 +dnl Copyright (C) 2002-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_STRCASE], -[ - gl_FUNC_STRCASECMP - gl_FUNC_STRNCASECMP -]) - -AC_DEFUN([gl_FUNC_STRCASECMP], -[ - AC_REQUIRE([gl_STRINGS_H_DEFAULTS]) - AC_CHECK_FUNCS([strcasecmp]) - if test $ac_cv_func_strcasecmp = no; then - HAVE_STRCASECMP=0 - fi -]) - AC_DEFUN([gl_FUNC_STRNCASECMP], [ AC_REQUIRE([gl_STRINGS_H_DEFAULTS]) @@ -36,11 +21,6 @@ AC_DEFUN([gl_FUNC_STRNCASECMP] fi ]) -# Prerequisites of lib/strcasecmp.c. -AC_DEFUN([gl_PREREQ_STRCASECMP], [ - : -]) - # Prerequisites of lib/strncasecmp.c. AC_DEFUN([gl_PREREQ_STRNCASECMP], [ : diff --git a/modules/argp b/modules/argp index 8b4e3e297b..caff9430cb 100644 --- a/modules/argp +++ b/modules/argp @@ -28,7 +28,7 @@ sysexits-h malloc-gnu mempcpy strndup -strcase +strcasecmp extensions vsnprintf sleep diff --git a/modules/strcase b/modules/strcase index 4d90a042a5..91bdd02d39 100644 --- a/modules/strcase +++ b/modules/strcase @@ -1,32 +1,15 @@ Description: -Case-insensitive string comparison functions. +Case-insensitive string comparison functions for unibyte locales. Files: -lib/strcasecmp.c -lib/strncasecmp.c -m4/strcase.m4 Depends-on: -strings-h +strcasecmp +strncasecmp configure.ac: -gl_STRCASE -gl_CONDITIONAL([GL_COND_OBJ_STRCASECMP], [test $HAVE_STRCASECMP = 0]) -AM_COND_IF([GL_COND_OBJ_STRCASECMP], [ - gl_PREREQ_STRCASECMP -]) -gl_CONDITIONAL([GL_COND_OBJ_STRNCASECMP], [test $HAVE_STRNCASECMP = 0]) -AM_COND_IF([GL_COND_OBJ_STRNCASECMP], [ - gl_PREREQ_STRNCASECMP -]) Makefile.am: -if GL_COND_OBJ_STRCASECMP -lib_SOURCES += strcasecmp.c -endif -if GL_COND_OBJ_STRNCASECMP -lib_SOURCES += strncasecmp.c -endif Include: <strings.h> diff --git a/modules/strcasecmp b/modules/strcasecmp new file mode 100644 index 0000000000..b226990b2a --- /dev/null +++ b/modules/strcasecmp @@ -0,0 +1,30 @@ +Description: +Case-insensitive string comparison function for unibyte locales. + +Files: +lib/strcasecmp.c +m4/strcasecmp.m4 + +Depends-on: +strings-h + +configure.ac: +gl_FUNC_STRCASECMP +gl_CONDITIONAL([GL_COND_OBJ_STRCASECMP], [test $HAVE_STRCASECMP = 0]) +AM_COND_IF([GL_COND_OBJ_STRCASECMP], [ + gl_PREREQ_STRCASECMP +]) + +Makefile.am: +if GL_COND_OBJ_STRCASECMP +lib_SOURCES += strcasecmp.c +endif + +Include: +<strings.h> + +License: +LGPLv2+ + +Maintainer: +all diff --git a/modules/strcasestr-simple b/modules/strcasestr-simple index 050bd81903..f944425ff0 100644 --- a/modules/strcasestr-simple +++ b/modules/strcasestr-simple @@ -9,7 +9,7 @@ m4/strcasestr.m4 Depends-on: string-h bool -strcase +strncasecmp memchr memcmp extensions diff --git a/modules/strncasecmp b/modules/strncasecmp new file mode 100644 index 0000000000..5fca265bad --- /dev/null +++ b/modules/strncasecmp @@ -0,0 +1,30 @@ +Description: +Case-insensitive string comparison function for unibyte locales. + +Files: +lib/strncasecmp.c +m4/strncasecmp.m4 + +Depends-on: +strings-h + +configure.ac: +gl_FUNC_STRNCASECMP +gl_CONDITIONAL([GL_COND_OBJ_STRNCASECMP], [test $HAVE_STRNCASECMP = 0]) +AM_COND_IF([GL_COND_OBJ_STRNCASECMP], [ + gl_PREREQ_STRNCASECMP +]) + +Makefile.am: +if GL_COND_OBJ_STRNCASECMP +lib_SOURCES += strncasecmp.c +endif + +Include: +<strings.h> + +License: +LGPLv2+ + +Maintainer: +all diff --git a/modules/strptime b/modules/strptime index 9ebb97e2fe..67296f76c8 100644 --- a/modules/strptime +++ b/modules/strptime @@ -11,7 +11,7 @@ time-h extensions sys_time-h [test $HAVE_STRPTIME = 0] string-h [test $HAVE_STRPTIME = 0] -strcase [test $HAVE_STRPTIME = 0] +strncasecmp [test $HAVE_STRPTIME = 0] bool [test $HAVE_STRPTIME = 0] time_r [test $HAVE_STRPTIME = 0] -- 2.43.0
>From c17d70aaaebfc79e4d5cc9b490b0cc7d43b5cd42 Mon Sep 17 00:00:00 2001 From: Bruno Haible <br...@clisp.org> Date: Sun, 16 Feb 2025 12:30:58 +0100 Subject: [PATCH 2/3] strings-h: Don't declare strcasecmp, strncasecmp without the module. * lib/strings.in.h (strcasecmp): Don't declare if module 'strcasecmp' is not present. (strncasecmp): Don't declare if module 'strncasecmp' is not present. * m4/strings_h.m4 (gl_STRINGS_H_REQUIRE_DEFAULTS): Initialize GNULIB_STRCASECMP, GNULIB_STRNCASECMP. * modules/strings-h (Makefile.am): Substitute GNULIB_STRCASECMP, GNULIB_STRNCASECMP. --- ChangeLog | 11 +++++++++++ lib/strings.in.h | 16 +++++++++------- m4/strings_h.m4 | 4 +++- modules/strings-h | 2 ++ 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 37255b17ea..65b34ef3fc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2025-02-16 Bruno Haible <br...@clisp.org> + + strings-h: Don't declare strcasecmp, strncasecmp without the module. + * lib/strings.in.h (strcasecmp): Don't declare if module 'strcasecmp' is + not present. + (strncasecmp): Don't declare if module 'strncasecmp' is not present. + * m4/strings_h.m4 (gl_STRINGS_H_REQUIRE_DEFAULTS): Initialize + GNULIB_STRCASECMP, GNULIB_STRNCASECMP. + * modules/strings-h (Makefile.am): Substitute GNULIB_STRCASECMP, + GNULIB_STRNCASECMP. + 2025-02-16 Bruno Haible <br...@clisp.org> strcasecmp, strncasecmp: New modules. diff --git a/lib/strings.in.h b/lib/strings.in.h index f99b7c95e8..d7bd1ae917 100644 --- a/lib/strings.in.h +++ b/lib/strings.in.h @@ -58,8 +58,8 @@ extern "C" { #endif - /* Find the index of the least-significant set bit. */ #if @GNULIB_FFS@ +/* Find the index of the least-significant set bit. */ # if !@HAVE_FFS@ _GL_FUNCDECL_SYS (ffs, int, (int i), ); # endif @@ -72,15 +72,16 @@ _GL_WARN_ON_USE (ffs, "ffs is not portable - use the ffs module"); # endif #endif +#if @GNULIB_STRCASECMP@ /* Compare strings S1 and S2, ignoring case, returning less than, equal to or greater than zero if S1 is lexicographically less than, equal to or greater than S2. Note: This function does not work in multibyte locales. */ -#if ! @HAVE_STRCASECMP@ +# if ! @HAVE_STRCASECMP@ extern int strcasecmp (char const *s1, char const *s2) _GL_ARG_NONNULL ((1, 2)); -#endif -#if defined GNULIB_POSIXCHECK +# endif +#elif defined GNULIB_POSIXCHECK /* strcasecmp() does not work with multibyte strings: POSIX says that it operates on "strings", and "string" in POSIX is defined as a sequence of bytes, not of characters. */ @@ -95,15 +96,16 @@ _GL_WARN_ON_USE (strcasecmp, "strcasecmp cannot work correctly on character " # endif #endif +#if @GNULIB_STRNCASECMP@ /* Compare no more than N bytes of strings S1 and S2, ignoring case, returning less than, equal to or greater than zero if S1 is lexicographically less than, equal to or greater than S2. Note: This function cannot work correctly in multibyte locales. */ -#if ! @HAVE_DECL_STRNCASECMP@ +# if ! @HAVE_DECL_STRNCASECMP@ extern int strncasecmp (char const *s1, char const *s2, size_t n) _GL_ARG_NONNULL ((1, 2)); -#endif -#if defined GNULIB_POSIXCHECK +# endif +#elif defined GNULIB_POSIXCHECK /* strncasecmp() does not work with multibyte strings: POSIX says that it operates on "strings", and "string" in POSIX is defined as a sequence of bytes, not of characters. */ diff --git a/m4/strings_h.m4 b/m4/strings_h.m4 index c6f40fcdfa..25596aa445 100644 --- a/m4/strings_h.m4 +++ b/m4/strings_h.m4 @@ -1,5 +1,5 @@ # strings_h.m4 -# serial 9 +# serial 10 dnl Copyright (C) 2007, 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, @@ -50,6 +50,8 @@ AC_DEFUN([gl_STRINGS_H_REQUIRE_DEFAULTS] [ m4_defun(GL_MODULE_INDICATOR_PREFIX[_STRINGS_H_MODULE_INDICATOR_DEFAULTS], [ gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FFS]) + gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STRCASECMP]) + gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STRNCASECMP]) ]) m4_require(GL_MODULE_INDICATOR_PREFIX[_STRINGS_H_MODULE_INDICATOR_DEFAULTS]) AC_REQUIRE([gl_STRINGS_H_DEFAULTS]) diff --git a/modules/strings-h b/modules/strings-h index ad05ba3314..7b3cc6ad44 100644 --- a/modules/strings-h +++ b/modules/strings-h @@ -33,6 +33,8 @@ strings.h: strings.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(WARN_ON_USE -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ -e 's|@''NEXT_STRINGS_H''@|$(NEXT_STRINGS_H)|g' \ -e 's/@''GNULIB_FFS''@/$(GNULIB_FFS)/g' \ + -e 's/@''GNULIB_STRCASECMP''@/$(GNULIB_STRCASECMP)/g' \ + -e 's/@''GNULIB_STRNCASECMP''@/$(GNULIB_STRNCASECMP)/g' \ -e 's|@''HAVE_FFS''@|$(HAVE_FFS)|g' \ -e 's|@''HAVE_STRCASECMP''@|$(HAVE_STRCASECMP)|g' \ -e 's|@''HAVE_DECL_STRNCASECMP''@|$(HAVE_DECL_STRNCASECMP)|g' \ -- 2.43.0
>From f656293f0e76f95fd77fbae7c1d356e6449d5d90 Mon Sep 17 00:00:00 2001 From: Bruno Haible <br...@clisp.org> Date: Sun, 16 Feb 2025 13:02:25 +0100 Subject: [PATCH 3/3] 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. --- ChangeLog | 31 +++++++++++++++++++ doc/c-locale.texi | 15 ++++++--- doc/c-strcasecmp.texi | 29 +++++++++++++++++ doc/{c-strcase.texi => c-strncasecmp.texi} | 19 +++++------- lib/strings.in.h | 4 +-- modules/c-strcase | 7 ++--- modules/c-strcasecmp | 23 ++++++++++++++ modules/c-strcasecmp-tests | 21 +++++++++++++ modules/c-strcaseeq | 2 +- modules/c-strcasestr | 2 +- modules/c-strncasecmp | 23 ++++++++++++++ .../{c-strcase-tests => c-strncasecmp-tests} | 8 ++--- modules/iconv_open | 2 +- modules/nl_langinfo-tests | 2 +- modules/propername | 2 +- modules/propername-lite | 2 +- modules/striconv | 2 +- modules/striconveh | 2 +- modules/striconveha | 2 +- tests/test-c-strcasecmp.sh | 18 +++++++++++ ...est-c-strcase.sh => test-c-strncasecmp.sh} | 3 -- 21 files changed, 179 insertions(+), 40 deletions(-) create mode 100644 doc/c-strcasecmp.texi rename doc/{c-strcase.texi => c-strncasecmp.texi} (62%) create mode 100644 modules/c-strcasecmp create mode 100644 modules/c-strcasecmp-tests create mode 100644 modules/c-strncasecmp rename modules/{c-strcase-tests => c-strncasecmp-tests} (63%) create mode 100755 tests/test-c-strcasecmp.sh rename tests/{test-c-strcase.sh => test-c-strncasecmp.sh} (69%) diff --git a/ChangeLog b/ChangeLog index 65b34ef3fc..5829c3bd9e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,34 @@ +2025-02-16 Bruno Haible <br...@clisp.org> + + 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 <br...@clisp.org> 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 @@ @menu * c-ctype:: -* c-strcase:: * c-strcaseeq:: +* c-strcasecmp:: +* c-strncasecmp:: * c-strcasestr:: * c-strstr:: * c-strtod:: @@ -28,14 +29,18 @@ @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 <https://www.gnu.org/licenses/fdl-1.3.en.html>. + +@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{<strings.h>}, 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{<strings.h>} +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 <https://www.gnu.org/licenses/fdl-1.3.en.html>. -@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{<strings.h>}, 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{<strings.h>} support only unibyte locales; -@mindex mbscasecmp +Note: The function @code{strncasecmp} from @code{<strings.h>} +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 -- 2.43.0