X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fstrsep.c;h=77dcb9972d35ff3b0485c892eeddb437d3f6aa3c;hb=81979bc8e213e442acf9f2bef9f6e227602c5b70;hp=40c2939c8e461626d0320a0e02f00de38cb050b4;hpb=4b560b1235fa3640920aa52d24c2b652f6decfb7;p=gnulib.git diff --git a/lib/strsep.c b/lib/strsep.c index 40c2939c8..77dcb9972 100644 --- a/lib/strsep.c +++ b/lib/strsep.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2004 Free Software Foundation, Inc. +/* Copyright (C) 2004, 2007, 2009-2011 Free Software Foundation, Inc. Written by Yoann Vandoorselaere . @@ -17,35 +17,38 @@ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifdef HAVE_CONFIG_H -#include +# include #endif /* Specification. */ -#include "strsep.h" - #include -#include "strpbrk.h" - char * strsep (char **stringp, const char *delim) { char *start = *stringp; char *ptr; - if (!start) + if (start == NULL) return NULL; - if (!*delim) - ptr = start + strlen (start); + /* Optimize the case of no delimiters. */ + if (delim[0] == '\0') + { + *stringp = NULL; + return start; + } + + /* Optimize the case of one delimiter. */ + if (delim[1] == '\0') + ptr = strchr (start, delim[0]); else + /* The general case. */ + ptr = strpbrk (start, delim); + if (ptr == NULL) { - ptr = strpbrk (start, delim); - if (!ptr) - { - *stringp = NULL; - return start; - } + *stringp = NULL; + return start; } *ptr = '\0';