changeset 8103:df6746e056ee

New module 'mbscspn'.
author Bruno Haible <bruno@clisp.org>
date Mon, 05 Feb 2007 03:06:40 +0000
parents 3e7efcdc6568
children 9d0175f6442d
files ChangeLog MODULES.html.sh lib/string_.h m4/string_h.m4 modules/string
diffstat 5 files changed, 36 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 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.
--- a/MODULES.html.sh
+++ b/MODULES.html.sh
@@ -2165,6 +2165,7 @@
   func_module mbsstr
   func_module mbscasecmp
   func_module mbscasestr
+  func_module mbscspn
   func_module mbswidth
   func_module memcasecmp
   func_module memcoll
--- a/lib/string_.h
+++ b/lib/string_.h
@@ -201,6 +201,17 @@
 # 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 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
 }
--- a/m4/string_h.m4
+++ b/m4/string_h.m4
@@ -72,4 +72,5 @@
   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])
 ])
--- a/modules/string
+++ b/modules/string
@@ -26,6 +26,7 @@
 	      -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' \