Mercurial > hg > octave-nkf > gnulib-hg
changeset 5292:facb079a01da
New module 'strsep'.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Fri, 01 Oct 2004 16:38:25 +0000 |
parents | 2b9cda789a2d |
children | 3e17fb121416 |
files | ChangeLog MODULES.html.sh lib/ChangeLog lib/strsep.c lib/strsep.h m4/ChangeLog m4/strsep.m4 modules/strsep |
diffstat | 8 files changed, 159 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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.
--- a/MODULES.html.sh +++ b/MODULES.html.sh @@ -1519,6 +1519,7 @@ func_module strdup func_module strnlen func_module strndup + func_module strsep #func_module fstrcmp func_module xstrndup func_end_table
--- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -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.
new file mode 100644 --- /dev/null +++ b/lib/strsep.c @@ -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; +}
new file mode 100644 --- /dev/null +++ b/lib/strsep.h @@ -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_ */
--- a/m4/ChangeLog +++ b/m4/ChangeLog @@ -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.
new file mode 100644 --- /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], [:])
new file mode 100644 --- /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