changeset 8085:452a78f76352

New module 'mbsrchr'.
author Bruno Haible <bruno@clisp.org>
date Mon, 05 Feb 2007 01:16:13 +0000
parents 26bd958c1cd1
children 5814790bde53
files ChangeLog MODULES.html.sh lib/string_.h m4/string_h.m4 modules/string
diffstat 5 files changed, 34 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2007-02-04  Bruno Haible  <bruno@clisp.org>
+
+	New module mbsrchr.
+	* modules/mbsrchr: New file.
+	* lib/mbsrchr.c: New file.
+	* lib/string_.h (strrchr): Add a conditional link warning.
+	(mbsrchr): New declaration.
+	* m4/mbsrchr.m4: New file.
+	* m4/string_h.m4 (gl_STRING_MODULE_INDICATOR_DEFAULTS): Initialize
+	GNULIB_MBSRCHR.
+	* modules/string (string.h): Also substitute GNULIB_MBSRCHR.
+	* MODULES.html.sh (Internationalization functions): Add mbsrchr.
+
 2007-02-04  Bruno Haible  <bruno@clisp.org>
 
 	New module mbschr.
--- a/MODULES.html.sh
+++ b/MODULES.html.sh
@@ -2162,6 +2162,7 @@
   func_module localcharset
   func_module hard-locale
   func_module mbschr
+  func_module mbsrchr
   func_module mbswidth
   func_module memcasecmp
   func_module memcoll
--- a/lib/string_.h
+++ b/lib/string_.h
@@ -213,6 +213,15 @@
 # define strpbrk strpbrk_is_unportable__use_gnulib_module_strpbrk_for_portability
 #endif
 
+#if defined GNULIB_POSIXCHECK
+/* strrchr() does not work with multibyte strings if the locale encoding is
+   GB18030 and the character to be searched is a digit.  */
+# undef strrchr
+# define strrchr(s,c) \
+    (GL_LINK_WARNING ("strrchr cannot work correctly on character strings in some multibyte locales - use mbsrchr if you care about internationalization"), \
+     strrchr (s, c))
+#endif
+
 /* Search the next delimiter (char listed in DELIM) starting at *STRINGP.
    If one is found, overwrite it with a NUL, and advance *STRINGP
    to point to the next char after it.  Otherwise, set *STRINGP to NULL.
@@ -317,6 +326,15 @@
 extern char * mbschr (const char *string, int c);
 #endif
 
+#if @GNULIB_MBSRCHR@
+/* Locate the last single-byte character C in the character string STRING,
+   and return a pointer to it.  Return NULL if C is not found in STRING.
+   Unlike strrchr(), this function works correctly in multibyte locales with
+   encodings such as GB18030.  */
+# define mbsrchr rpl_mbsrchr /* avoid collision with HP-UX function */
+extern char * mbsrchr (const char *string, int c);
+#endif
+
 
 #ifdef __cplusplus
 }
--- a/m4/string_h.m4
+++ b/m4/string_h.m4
@@ -71,4 +71,5 @@
   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])
 ])
--- a/modules/string
+++ b/modules/string
@@ -22,6 +22,7 @@
 	{ echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \
 	  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_MEMMEM''@|$(GNULIB_MEMMEM)|g' \
 	      -e 's|@''GNULIB_MEMPCPY''@|$(GNULIB_MEMPCPY)|g' \
 	      -e 's|@''GNULIB_MEMRCHR''@|$(GNULIB_MEMRCHR)|g' \