summaryrefslogtreecommitdiffstats
path: root/librdfa/strtok_r.c
blob: f07f9fbb10a0b05e526ca4ca9221f87fcc2c9a3e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/* This file is in the public domain */

#ifdef HAVE_CONFIG_H
#  include <config.h>
#endif

#include <string.h>
#include "strtok_r.h"

#ifdef NEED_RDFA_STRTOK_R

char *
rdfa_strtok_r(char *str, const char *delim, char **saveptr)
{
   char *p;

   if (str == NULL)
      str = *saveptr;

   if (str == NULL)
      return NULL;

   while (*str && strchr(delim, *str))
      str++;

   if (*str == '\0')
   {
      *saveptr = NULL;
      return NULL;
   }

   p = str;
   while (*p && !strchr(delim, *p))
      p++;

   if (*p == '\0')
      *saveptr = NULL;
   else
   {
      *p = '\0';
      p++;
      *saveptr = p;
   }

   return str;
}

#else /* ! NEED_RDFA_STRTOK_R */

typedef int blah; /* "ISO C forbids an empty translation unit" */

#endif /* NEED_RDFA_STRTOK_R */