From 68f96cd3ccba2a204c40260321a8832f2eb97092 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Fri, 1 Oct 2004 16:38:25 +0000 Subject: [PATCH] New module 'strsep'. --- ChangeLog | 8 +++++++ MODULES.html.sh | 1 + lib/ChangeLog | 5 +++++ lib/strsep.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++ lib/strsep.h | 43 +++++++++++++++++++++++++++++++++++++ m4/ChangeLog | 4 ++++ m4/strsep.m4 | 17 +++++++++++++++ modules/strsep | 25 ++++++++++++++++++++++ 8 files changed, 159 insertions(+) create mode 100644 lib/strsep.c create mode 100644 lib/strsep.h create mode 100644 m4/strsep.m4 create mode 100644 modules/strsep diff --git a/ChangeLog b/ChangeLog index 249ad00aae..cd8bad00ee 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2004-10-01 Bruno Haible + + * MODULES.html.sh: Add strsep. + +2004-10-01 Yoann Vandoorselaere + + * modules/strsep: New file. + 2004-09-30 Paul Eggert * MODULES.html.sh (Support for systems lacking ISO C 99): Add snprintf. diff --git a/MODULES.html.sh b/MODULES.html.sh index 50743d2b66..eeabdb94ac 100755 --- a/MODULES.html.sh +++ b/MODULES.html.sh @@ -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 diff --git a/lib/ChangeLog b/lib/ChangeLog index 7d2c82872e..00a2e7c8bf 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,8 @@ +2004-10-01 Yoann Vandoorselaere + + * strsep.h: New file. + * strsep.c: New file. + 2004-10-01 Simon Josefsson * snprintf.c (snprintf): Handle size==0. diff --git a/lib/strsep.c b/lib/strsep.c new file mode 100644 index 0000000000..757bc5f010 --- /dev/null +++ b/lib/strsep.c @@ -0,0 +1,56 @@ +/* Copyright (C) 2004 Free Software Foundation, Inc. + * Written by Yoann Vandoorselaere + * + * 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 +#endif + +/* Specification. */ +#include "strsep.h" + +#include + +#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 index 0000000000..87351ff4a7 --- /dev/null +++ b/lib/strsep.h @@ -0,0 +1,43 @@ +/* Copyright (C) 2004 Free Software Foundation, Inc. + * Written by Yoann Vandoorselaere + * + * 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 + +/* 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_ */ diff --git a/m4/ChangeLog b/m4/ChangeLog index 8137cbba34..7e58d06dbe 100644 --- a/m4/ChangeLog +++ b/m4/ChangeLog @@ -1,3 +1,7 @@ +2004-10-01 Yoann Vandoorselaere + + * strsep.m4: New file. + 2004-09-30 Simon Josefsson * snprintf.m4: New file. diff --git a/m4/strsep.m4 b/m4/strsep.m4 new file mode 100644 index 0000000000..430a25805f --- /dev/null +++ b/m4/strsep.m4 @@ -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 index 0000000000..9324289781 --- /dev/null +++ b/modules/strsep @@ -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 -- 2.30.2