From 0e6e2d08f8fb82246767c5e671dea720934af1c0 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Mon, 5 Feb 2007 01:36:34 +0000 Subject: [PATCH] New module 'mbsstr'. Remove module 'strstr'. --- ChangeLog | 21 +++++++++++++++++++++ MODULES.html.sh | 2 +- lib/mbsstr.c | 5 +++-- lib/string_.h | 26 ++++++++++++++------------ m4/mbsstr.m4 | 16 ++++++++++++++++ m4/string_h.m4 | 3 +-- m4/strstr.m4 | 21 --------------------- modules/mbsstr | 28 ++++++++++++++++++++++++++++ modules/string | 3 +-- modules/strstr | 26 -------------------------- 10 files changed, 85 insertions(+), 66 deletions(-) create mode 100644 m4/mbsstr.m4 delete mode 100644 m4/strstr.m4 create mode 100644 modules/mbsstr delete mode 100644 modules/strstr diff --git a/ChangeLog b/ChangeLog index 9c8f82f60..7edacf88e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,26 @@ 2007-02-04 Bruno Haible + New module mbsstr. Remove module strstr. + * modules/mbsstr: New file. + * modules/strstr: Remove file. + * lib/mbsstr.c: Renamed from lib/strstr.c. + (mbsstr): Renamed from strstr. + * lib/string_.h (strstr): Remove declaration. Change the conditional + link warning. + (mbsstr): New declaration. + * m4/mbsstr.m4: New file. + * m4/strstr.m4: Remove file. + * m4/string_h.m4 (gl_HEADER_STRING_H_DEFAULTS): Don't initialize + REPLACE_STRSTR. + (gl_STRING_MODULE_INDICATOR_DEFAULTS): Initialize GNULIB_MBSSTR. + Don't initialize GNULIB_STRSTR. + * modules/string (string.h): Also substitute GNULIB_MBSSTR. Don't + substitute GNULIB_STRSTR and REPLACE_STRSTR. + * MODULES.html.sh (Internationalization functions): Add mbsstr. + (Support for systems lacking ANSI C 89): Remove strstr. + +2007-02-04 Bruno Haible + New module mbsrchr. * modules/mbsrchr: New file. * lib/mbsrchr.c: New file. diff --git a/MODULES.html.sh b/MODULES.html.sh index 303f8a4e9..b11f90fa7 100755 --- a/MODULES.html.sh +++ b/MODULES.html.sh @@ -1502,7 +1502,6 @@ func_all_modules () func_module memset func_module strcspn func_module strpbrk - func_module strstr func_module strerror func_module mktime func_end_table @@ -2163,6 +2162,7 @@ func_all_modules () func_module hard-locale func_module mbschr func_module mbsrchr + func_module mbsstr func_module mbswidth func_module memcasecmp func_module memcoll diff --git a/lib/mbsstr.c b/lib/mbsstr.c index 2ee16507a..84b828950 100644 --- a/lib/mbsstr.c +++ b/lib/mbsstr.c @@ -27,9 +27,10 @@ # include "mbuiter.h" #endif -/* Find the first occurrence of NEEDLE in HAYSTACK. */ +/* Find the first occurrence of the character string NEEDLE in the character + string HAYSTACK. Return NULL if NEEDLE is not found in HAYSTACK. */ char * -strstr (const char *haystack, const char *needle) +mbsstr (const char *haystack, const char *needle) { /* Be careful not to look at the entire extent of haystack or needle until needed. This is useful because of these two cases: diff --git a/lib/string_.h b/lib/string_.h index 36d4d054f..6b99fb2d4 100644 --- a/lib/string_.h +++ b/lib/string_.h @@ -247,20 +247,14 @@ extern char *strsep (char **restrict __stringp, char const *restrict __delim); # define strsep strsep_is_unportable__use_gnulib_module_strsep_for_portability #endif -/* Find the first occurrence of NEEDLE in HAYSTACK. - No known system has a strstr() function that works correctly in - multibyte locales. Therefore use our version always, if the strstr - module is available. */ -#if @GNULIB_STRSTR@ -# if @REPLACE_STRSTR@ -# undef strstr -# define strstr rpl_strstr -extern char *strstr (char const *__haystack, char const *__needle); -# endif -#elif defined GNULIB_POSIXCHECK +#if defined GNULIB_POSIXCHECK +/* strstr() does not work with multibyte strings if the locale encoding is + different from UTF-8: + POSIX says that it operates on "strings", and "string" in POSIX is defined + as a sequence of bytes, not of characters. */ # undef strstr # define strstr(a,b) \ - (GL_LINK_WARNING ("strstr is often incorrectly implemented for multibyte locales - use gnulib module 'strstr' for correct and portable internationalization"), \ + (GL_LINK_WARNING ("strstr cannot work correctly on character strings in most multibyte locales - use mbsstr if you care about internationalization"), \ strstr (a, b)) #endif @@ -335,6 +329,14 @@ extern char * mbschr (const char *string, int c); extern char * mbsrchr (const char *string, int c); #endif +#if @GNULIB_MBSSTR@ +/* Find the first occurrence of the character string NEEDLE in the character + string HAYSTACK. Return NULL if NEEDLE is not found in HAYSTACK. + Unlike strstr(), this function works correctly in multibyte locales with + encodings different from UTF-8. */ +extern char * mbsstr (const char *haystack, const char *needle); +#endif + #ifdef __cplusplus } diff --git a/m4/mbsstr.m4 b/m4/mbsstr.m4 new file mode 100644 index 000000000..cec117f45 --- /dev/null +++ b/m4/mbsstr.m4 @@ -0,0 +1,16 @@ +# mbsstr.m4 serial 1 +dnl Copyright (C) 2007 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_MBSSTR], +[ + gl_PREREQ_MBSSTR +]) + +# Prerequisites of lib/mbsstr.c. +AC_DEFUN([gl_PREREQ_MBSSTR], [ + AC_REQUIRE([gl_FUNC_MBRTOWC]) + : +]) diff --git a/m4/string_h.m4 b/m4/string_h.m4 index bb0e7525d..152a6ad71 100644 --- a/m4/string_h.m4 +++ b/m4/string_h.m4 @@ -42,7 +42,6 @@ AC_DEFUN([gl_HEADER_STRING_H_DEFAULTS], HAVE_STRSEP=1; AC_SUBST([HAVE_STRSEP]) HAVE_DECL_STRTOK_R=1; AC_SUBST([HAVE_DECL_STRTOK_R]) REPLACE_STRCASECMP=0; AC_SUBST([REPLACE_STRCASECMP]) - REPLACE_STRSTR=0; AC_SUBST([REPLACE_STRSTR]) REPLACE_STRCASESTR=0; AC_SUBST([REPLACE_STRCASESTR]) ]) @@ -67,9 +66,9 @@ AC_DEFUN([gl_STRING_MODULE_INDICATOR_DEFAULTS], GNULIB_STRNLEN=0; AC_SUBST([GNULIB_STRNLEN]) GNULIB_STRPBRK=0; AC_SUBST([GNULIB_STRPBRK]) GNULIB_STRSEP=0; AC_SUBST([GNULIB_STRSEP]) - GNULIB_STRSTR=0; AC_SUBST([GNULIB_STRSTR]) GNULIB_STRCASESTR=0; AC_SUBST([GNULIB_STRCASESTR]) GNULIB_STRTOK_R=0; AC_SUBST([GNULIB_STRTOK_R]) GNULIB_MBSCHR=0; AC_SUBST([GNULIB_MBSCHR]) GNULIB_MBSRCHR=0; AC_SUBST([GNULIB_MBSRCHR]) + GNULIB_MBSSTR=0; AC_SUBST([GNULIB_MBSSTR]) ]) diff --git a/m4/strstr.m4 b/m4/strstr.m4 deleted file mode 100644 index 97eb0a8bd..000000000 --- a/m4/strstr.m4 +++ /dev/null @@ -1,21 +0,0 @@ -# strstr.m4 serial 6 -dnl Copyright (C) 2002-2003, 2005, 2007 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_STRSTR], -[ - AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS]) - dnl No known system has a strstr() function that works correctly in - dnl multibyte locales. Therefore we use our version always. - AC_LIBOBJ(strstr) - REPLACE_STRSTR=1 - gl_PREREQ_STRSTR -]) - -# Prerequisites of lib/strstr.c. -AC_DEFUN([gl_PREREQ_STRSTR], [ - AC_REQUIRE([gl_FUNC_MBRTOWC]) - : -]) diff --git a/modules/mbsstr b/modules/mbsstr new file mode 100644 index 000000000..bfcd47ae6 --- /dev/null +++ b/modules/mbsstr @@ -0,0 +1,28 @@ +Description: +mbsstr() function: search for a substring in a string. + +Files: +lib/mbsstr.c +m4/mbsstr.m4 +m4/mbrtowc.m4 + +Depends-on: +mbuiter +string + +configure.ac: +gl_FUNC_MBSSTR +gl_STRING_MODULE_INDICATOR([mbsstr]) + +Makefile.am: +lib_SOURCES += mbsstr.c + +Include: + + +License: +LGPL + +Maintainer: +Bruno Haible + diff --git a/modules/string b/modules/string index 764496aed..3eac82973 100644 --- a/modules/string +++ b/modules/string @@ -23,6 +23,7 @@ string.h: string_.h sed -e 's|@''ABSOLUTE_STRING_H''@|$(ABSOLUTE_STRING_H)|g' \ -e 's|@''GNULIB_MBSCHR''@|$(GNULIB_MBSCHR)|g' \ -e 's|@''GNULIB_MBSRCHR''@|$(GNULIB_MBSRCHR)|g' \ + -e 's|@''GNULIB_MBSSTR''@|$(GNULIB_MBSSTR)|g' \ -e 's|@''GNULIB_MEMMEM''@|$(GNULIB_MEMMEM)|g' \ -e 's|@''GNULIB_MEMPCPY''@|$(GNULIB_MEMPCPY)|g' \ -e 's|@''GNULIB_MEMRCHR''@|$(GNULIB_MEMRCHR)|g' \ @@ -35,7 +36,6 @@ string.h: string_.h -e 's|@''GNULIB_STRNLEN''@|$(GNULIB_STRNLEN)|g' \ -e 's|@''GNULIB_STRPBRK''@|$(GNULIB_STRPBRK)|g' \ -e 's|@''GNULIB_STRSEP''@|$(GNULIB_STRSEP)|g' \ - -e 's|@''GNULIB_STRSTR''@|$(GNULIB_STRSTR)|g' \ -e 's|@''GNULIB_STRCASESTR''@|$(GNULIB_STRCASESTR)|g' \ -e 's|@''GNULIB_STRTOK_R''@|$(GNULIB_STRTOK_R)|g' \ -e 's|@''HAVE_DECL_MEMMEM''@|$(HAVE_DECL_MEMMEM)|g' \ @@ -53,7 +53,6 @@ string.h: string_.h -e 's|@''HAVE_STRSEP''@|$(HAVE_STRSEP)|g' \ -e 's|@''HAVE_DECL_STRTOK_R''@|$(HAVE_DECL_STRTOK_R)|g' \ -e 's|@''REPLACE_STRCASECMP''@|$(REPLACE_STRCASECMP)|g' \ - -e 's|@''REPLACE_STRSTR''@|$(REPLACE_STRSTR)|g' \ -e 's|@''REPLACE_STRCASESTR''@|$(REPLACE_STRCASESTR)|g' \ < $(srcdir)/string_.h; \ } > $@-t diff --git a/modules/strstr b/modules/strstr deleted file mode 100644 index 5e3f9fd47..000000000 --- a/modules/strstr +++ /dev/null @@ -1,26 +0,0 @@ -Description: -strstr() function: search for a substring in a string. - -Files: -lib/strstr.c -m4/strstr.m4 -m4/mbrtowc.m4 - -Depends-on: -mbuiter -string - -configure.ac: -gl_FUNC_STRSTR -gl_STRING_MODULE_INDICATOR([strstr]) - -Makefile.am: - -Include: - - -License: -LGPL - -Maintainer: -Bruno Haible, glibc -- 2.11.0