From f213651e6fa01f6a6ea19c0c6f71124d41035213 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Mon, 5 Feb 2007 01:16:13 +0000 Subject: [PATCH] New module 'mbsrchr'. --- ChangeLog | 13 +++++++++++++ MODULES.html.sh | 1 + lib/string_.h | 18 ++++++++++++++++++ m4/string_h.m4 | 1 + modules/string | 1 + 5 files changed, 34 insertions(+) diff --git a/ChangeLog b/ChangeLog index 1a4c56a8e..9c8f82f60 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,18 @@ 2007-02-04 Bruno Haible + 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 + New module mbschr. * modules/mbschr: New file. * lib/mbschr.c: New file. diff --git a/MODULES.html.sh b/MODULES.html.sh index c22c4f8f4..303f8a4e9 100755 --- a/MODULES.html.sh +++ b/MODULES.html.sh @@ -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 diff --git a/lib/string_.h b/lib/string_.h index e365810c8..36d4d054f 100644 --- a/lib/string_.h +++ b/lib/string_.h @@ -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 } diff --git a/m4/string_h.m4 b/m4/string_h.m4 index ab2efd4c9..bb0e7525d 100644 --- a/m4/string_h.m4 +++ b/m4/string_h.m4 @@ -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]) ]) diff --git a/modules/string b/modules/string index 5e9bd11b1..764496aed 100644 --- a/modules/string +++ b/modules/string @@ -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' \ -- 2.11.0