New module 'mbsrchr'.
authorBruno Haible <bruno@clisp.org>
Mon, 5 Feb 2007 01:16:13 +0000 (01:16 +0000)
committerBruno Haible <bruno@clisp.org>
Mon, 5 Feb 2007 01:16:13 +0000 (01:16 +0000)
ChangeLog
MODULES.html.sh
lib/string_.h
m4/string_h.m4
modules/string

index 1a4c56a..9c8f82f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,18 @@
 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.
        * modules/mbschr: New file.
        * lib/mbschr.c: New file.
index c22c4f8..303f8a4 100755 (executable)
@@ -2162,6 +2162,7 @@ func_all_modules ()
   func_module localcharset
   func_module hard-locale
   func_module mbschr
+  func_module mbsrchr
   func_module mbswidth
   func_module memcasecmp
   func_module memcoll
index e365810..36d4d05 100644 (file)
@@ -213,6 +213,15 @@ extern char *strpbrk (char const *__s, char const *__accept);
 # 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 *strtok_r (char *restrict __s, char const *restrict __sep,
 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
 }
index ab2efd4..bb0e752 100644 (file)
@@ -71,4 +71,5 @@ AC_DEFUN([gl_STRING_MODULE_INDICATOR_DEFAULTS],
   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])
 ])
index 5e9bd11..764496a 100644 (file)
@@ -22,6 +22,7 @@ string.h: string_.h
        { 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' \