New module 'strsep'.
authorBruno Haible <bruno@clisp.org>
Fri, 1 Oct 2004 16:38:25 +0000 (16:38 +0000)
committerBruno Haible <bruno@clisp.org>
Fri, 1 Oct 2004 16:38:25 +0000 (16:38 +0000)
ChangeLog
MODULES.html.sh
lib/ChangeLog
lib/strsep.c [new file with mode: 0644]
lib/strsep.h [new file with mode: 0644]
m4/ChangeLog
m4/strsep.m4 [new file with mode: 0644]
modules/strsep [new file with mode: 0644]

index 249ad00aae7d3941e28c9c7cd776425ea4cc9965..cd8bad00eeb6f27a108e28c0c6c4e0473a32a6c8 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2004-10-01  Bruno Haible  <bruno@clisp.org>
+
+       * MODULES.html.sh: Add strsep.
+
+2004-10-01  Yoann Vandoorselaere <yoann@prelude-ids.org>
+
+       * modules/strsep: New file.
+
 2004-09-30  Paul Eggert  <eggert@cs.ucla.edu>
 
        * MODULES.html.sh (Support for systems lacking ISO C 99): Add snprintf.
index 50743d2b66d5ab322d928ea8cf18cf4efd6e9645..eeabdb94acad7490d580ef0d03d2d8e636ac8bfb 100755 (executable)
@@ -1519,6 +1519,7 @@ func_all_modules ()
   func_module strdup
   func_module strnlen
   func_module strndup
+  func_module strsep
   #func_module fstrcmp
   func_module xstrndup
   func_end_table
index 7d2c82872e1e5e9b121ae2b6c81168f3cc3cbb0f..00a2e7c8bf01009da2982466ad57a613b55a4528 100644 (file)
@@ -1,3 +1,8 @@
+2004-10-01  Yoann Vandoorselaere <yoann@prelude-ids.org>
+
+       * strsep.h: New file.
+       * strsep.c: New file.
+
 2004-10-01  Simon Josefsson  <jas@extundo.com>
 
        * snprintf.c (snprintf): Handle size==0.
diff --git a/lib/strsep.c b/lib/strsep.c
new file mode 100644 (file)
index 0000000..757bc5f
--- /dev/null
@@ -0,0 +1,56 @@
+/* Copyright (C) 2004 Free Software Foundation, Inc.
+ * Written by Yoann Vandoorselaere <yoann@prelude-ids.org>
+ *
+ * The file is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This file is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this file; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+/* Specification.  */
+#include "strsep.h"
+
+#include <string.h>
+
+#include "strpbrk.h"
+
+char *
+strsep (char **stringp, const char *delim)
+{
+  char *start = *stringp;
+  char *ptr;
+
+  if (!start)
+    return NULL;
+
+  if (!*delim)
+    ptr = start + strlen (start);
+  else
+    {
+      ptr = strpbrk (start, delim);
+      if (!ptr)
+       {
+         *stringp = NULL;
+         return start;
+       }
+    }
+
+  *ptr = '\0';
+  *stringp = ptr + 1;
+
+  return start;
+}
diff --git a/lib/strsep.h b/lib/strsep.h
new file mode 100644 (file)
index 0000000..87351ff
--- /dev/null
@@ -0,0 +1,43 @@
+/* Copyright (C) 2004 Free Software Foundation, Inc.
+ * Written by Yoann Vandoorselaere <yoann@prelude-ids.org>
+ *
+ * The file is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This file is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this file; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ */
+
+#ifndef GNULIB_STRSEP_H_
+#define GNULIB_STRSEP_H_
+
+/*
+ * Get strsep, if available.
+ */
+#include <string.h>
+
+/* Searches the next delimiter (char listed in DELIM) starting at *STRINGP.
+   If one is found, it is overwritten with a NUL, and *STRINGP is advanced
+   to point to the next char after it.  Otherwise, *STRINGP is set to NULL.
+   If *STRINGP was already NULL, nothing happens.
+   Returns the old value of *STRINGP.
+
+   This is a variant of strtok() that is multithread-safe and supports
+   empty fields.
+
+   Caveat: It modifies the original string.
+   Caveat: It doesn't work with multibyte strings unless all of the delimiter
+           characters are ASCII characters < 0x30.  */
+
+extern char *strsep (char **stringp, const char *delim);
+
+#endif /* GNULIB_STRSEP_H_ */
index 8137cbba34baa924ea1eedb308a561f0bcb1746b..7e58d06dbe256fb51f53f44a6bcb1bb1e7279d50 100644 (file)
@@ -1,3 +1,7 @@
+2004-10-01  Yoann Vandoorselaere <yoann@prelude-ids.org>
+
+       * strsep.m4: New file.
+
 2004-09-30  Simon Josefsson  <jas@extundo.com>
 
        * snprintf.m4: New file.
diff --git a/m4/strsep.m4 b/m4/strsep.m4
new file mode 100644 (file)
index 0000000..430a258
--- /dev/null
@@ -0,0 +1,17 @@
+# strsep.m4 serial 1
+dnl Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
+dnl This file is free software, distributed under the terms of the GNU
+dnl General Public License.  As a special exception to the GNU General
+dnl Public License, this file may be distributed as part of a program
+dnl that contains a configuration script generated by Autoconf, under
+dnl the same distribution terms as the rest of that program.
+
+AC_DEFUN([gl_FUNC_STRSEP],
+[
+  AC_REPLACE_FUNCS(strsep)
+  AC_CHECK_DECLS_ONCE(strsep)
+  gl_PREREQ_STRSEP
+])
+
+# Prerequisites of lib/strsep.c.
+AC_DEFUN([gl_PREREQ_STRSEP], [:])
diff --git a/modules/strsep b/modules/strsep
new file mode 100644 (file)
index 0000000..9324289
--- /dev/null
@@ -0,0 +1,25 @@
+Description:
+strsep() function: extract token from string.
+
+Files:
+lib/strsep.h
+lib/strsep.c
+m4/strsep.m4
+
+Depends-on:
+strpbrk
+
+configure.ac:
+gl_FUNC_STRSEP
+
+Makefile.am:
+lib_SOURCES += strsep.h
+
+Include:
+"strsep.h"
+
+License:
+LGPL
+
+Maintainer:
+Yoann Vandoorselaere