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

index 2fc21db..1da2d79 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,18 @@
 2007-02-04  Bruno Haible  <bruno@clisp.org>
 
+       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  <bruno@clisp.org>
+
        New module mbscasestr, reduced goal of strcasestr.
        * modules/mbscasestr: New file.
        * lib/mbscasestr.c: New file, copied from lib/strcasestr.c.
index 715bc9d..5cf44b9 100755 (executable)
@@ -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
index 118a2d4..50ab672 100644 (file)
@@ -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
 }
index f89046a..ed06b9d 100644 (file)
@@ -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])
 ])
index 573c2c1..561eaef 100644 (file)
@@ -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' \