maint: update copyright
[gnulib.git] / lib / strsep.c
index 40c2939..525d09b 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2004 Free Software Foundation, Inc.
+/* Copyright (C) 2004, 2007, 2009-2014 Free Software Foundation, Inc.
 
    Written by Yoann Vandoorselaere <yoann@prelude-ids.org>.
 
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
+   along with this program; if not, see <http://www.gnu.org/licenses/>.  */
 
 #ifdef HAVE_CONFIG_H
-#include <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)
+  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';