projects
/
gnulib.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
vasnprintf test: Reduce code duplication.
[gnulib.git]
/
lib
/
strsep.c
diff --git
a/lib/strsep.c
b/lib/strsep.c
index
40c2939
..
6037f4d
100644
(file)
--- a/
lib/strsep.c
+++ b/
lib/strsep.c
@@
-1,4
+1,4
@@
-/* Copyright (C) 2004 Free Software Foundation, Inc.
+/* Copyright (C) 2004
, 2007, 2009, 2010
Free Software Foundation, Inc.
Written by Yoann Vandoorselaere <yoann@prelude-ids.org>.
Written by Yoann Vandoorselaere <yoann@prelude-ids.org>.
@@
-17,35
+17,38
@@
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
#ifdef HAVE_CONFIG_H
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
#ifdef HAVE_CONFIG_H
-#include <config.h>
+#
include <config.h>
#endif
/* Specification. */
#endif
/* Specification. */
-#include "strsep.h"
-
#include <string.h>
#include <string.h>
-#include "strpbrk.h"
-
char *
strsep (char **stringp, const char *delim)
{
char *start = *stringp;
char *ptr;
char *
strsep (char **stringp, const char *delim)
{
char *start = *stringp;
char *ptr;
- if (
!start
)
+ if (
start == NULL
)
return 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
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';
}
*ptr = '\0';