From f410f7db6dc24c9ecd0b1f86c7b897d5a90202f4 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Mon, 5 Feb 2007 03:06:40 +0000 Subject: [PATCH] New module 'mbscspn'. --- ChangeLog | 13 +++++++++++++ MODULES.html.sh | 1 + lib/string_.h | 20 ++++++++++++++++++++ m4/string_h.m4 | 1 + modules/string | 1 + 5 files changed, 36 insertions(+) diff --git a/ChangeLog b/ChangeLog index 2fc21db62..1da2d79c7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,18 @@ 2007-02-04 Bruno Haible + New module mbscspn. + * modules/mbscspn: New file. + * lib/mbscspn.c: New file. + * lib/string_.h (strcspn): Add a conditional link warning. + (mbscspn): New declaration. + * m4/mbscspn.m4: New file. + * m4/string_h.m4 (gl_STRING_MODULE_INDICATOR_DEFAULTS): Initialize + GNULIB_MBSCSPN. + * modules/string (string.h): Also substitute GNULIB_MBSCSPN. + * MODULES.html.sh (Internationalization functions): Add mbscspn. + +2007-02-04 Bruno Haible + New module mbscasestr, reduced goal of strcasestr. * modules/mbscasestr: New file. * lib/mbscasestr.c: New file, copied from lib/strcasestr.c. diff --git a/MODULES.html.sh b/MODULES.html.sh index 715bc9dc0..5cf44b97e 100755 --- a/MODULES.html.sh +++ b/MODULES.html.sh @@ -2165,6 +2165,7 @@ func_all_modules () func_module mbsstr func_module mbscasecmp func_module mbscasestr + func_module mbscspn func_module mbswidth func_module memcasecmp func_module memcoll diff --git a/lib/string_.h b/lib/string_.h index 118a2d4a2..50ab672e1 100644 --- a/lib/string_.h +++ b/lib/string_.h @@ -201,6 +201,17 @@ extern size_t strnlen (char const *__string, size_t __maxlen); # define strnlen strnlen_is_unportable__use_gnulib_module_strnlen_for_portability #endif +#if defined GNULIB_POSIXCHECK +/* strcspn() assumes the second argument is a list of single-byte characters. + Even in this simple case, it does not work with multibyte strings if the + locale encoding is GB18030 and one of the characters to be searched is a + digit. */ +# undef strcspn +# define strcspn(s,a) \ + (GL_LINK_WARNING ("strcspn cannot work correctly on character strings in multibyte locales - use mbscspn if you care about internationalization"), \ + strcspn (s, a)) +#endif + /* Find the first occurrence in S of any character in ACCEPT. */ #if @GNULIB_STRPBRK@ # if ! @HAVE_STRPBRK@ @@ -352,6 +363,15 @@ extern int mbscasecmp (const char *s1, const char *s2); extern char * mbscasestr (const char *haystack, const char *needle); #endif +#if @GNULIB_MBSCSPN@ +/* Find the first occurrence in the character string STRING of any character + in the character string ACCEPT. Return the number of bytes from the + beginning of the string to this occurrence, or to the end of the string + if none exists. + Unlike strcspn(), this function works correctly in multibyte locales. */ +extern size_t mbscspn (const char *string, const char *accept); +#endif + #ifdef __cplusplus } diff --git a/m4/string_h.m4 b/m4/string_h.m4 index f89046ac4..ed06b9d19 100644 --- a/m4/string_h.m4 +++ b/m4/string_h.m4 @@ -72,4 +72,5 @@ AC_DEFUN([gl_STRING_MODULE_INDICATOR_DEFAULTS], GNULIB_MBSSTR=0; AC_SUBST([GNULIB_MBSSTR]) GNULIB_MBSCASECMP=0; AC_SUBST([GNULIB_MBSCASECMP]) GNULIB_MBSCASESTR=0; AC_SUBST([GNULIB_MBSCASESTR]) + GNULIB_MBSCSPN=0; AC_SUBST([GNULIB_MBSCSPN]) ]) diff --git a/modules/string b/modules/string index 573c2c177..561eaef94 100644 --- a/modules/string +++ b/modules/string @@ -26,6 +26,7 @@ string.h: string_.h -e 's|@''GNULIB_MBSSTR''@|$(GNULIB_MBSSTR)|g' \ -e 's|@''GNULIB_MBSCASECMP''@|$(GNULIB_MBSCASECMP)|g' \ -e 's|@''GNULIB_MBSCASESTR''@|$(GNULIB_MBSCASESTR)|g' \ + -e 's|@''GNULIB_MBSCSPN''@|$(GNULIB_MBSCSPN)|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