changeset 8088:56a0105d8cf3

New module 'mbsstr'. Remove module 'strstr'.
author Bruno Haible <bruno@clisp.org>
date Mon, 05 Feb 2007 01:36:34 +0000
parents 9474e9077766
children 6a02aa86f4b4
files ChangeLog MODULES.html.sh lib/mbsstr.c lib/string_.h m4/mbsstr.m4 m4/string_h.m4 m4/strstr.m4 modules/mbsstr modules/string modules/strstr
diffstat 10 files changed, 85 insertions(+), 66 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,24 @@
+2007-02-04  Bruno Haible  <bruno@clisp.org>
+
+	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  <bruno@clisp.org>
 
 	New module mbsrchr.
--- a/MODULES.html.sh
+++ b/MODULES.html.sh
@@ -1502,7 +1502,6 @@
   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_module hard-locale
   func_module mbschr
   func_module mbsrchr
+  func_module mbsstr
   func_module mbswidth
   func_module memcasecmp
   func_module memcoll
--- 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:
--- a/lib/string_.h
+++ b/lib/string_.h
@@ -247,20 +247,14 @@
 # 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 * 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
 }
new file mode 100644
--- /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])
+  :
+])
--- a/m4/string_h.m4
+++ b/m4/string_h.m4
@@ -42,7 +42,6 @@
   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 @@
   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])
 ])
deleted file mode 100644
--- 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])
-  :
-])
new file mode 100644
--- /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:
+<string.h>
+
+License:
+LGPL
+
+Maintainer:
+Bruno Haible
+
--- a/modules/string
+++ b/modules/string
@@ -23,6 +23,7 @@
 	  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 @@
 	      -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 @@
 	      -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
deleted file mode 100644
--- 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:
-<string.h>
-
-License:
-LGPL
-
-Maintainer:
-Bruno Haible, glibc