SDL  2.0
SDL_strtokr.c File Reference
#include "../SDL_internal.h"
#include "SDL_stdinc.h"
+ Include dependency graph for SDL_strtokr.c:

Go to the source code of this file.

Functions

char * SDL_strtokr (char *s1, const char *s2, char **ptr)
 

Function Documentation

◆ SDL_strtokr()

char* SDL_strtokr ( char *  s1,
const char *  s2,
char **  ptr 
)

Definition at line 29 of file SDL_strtokr.c.

30 {
31 #if defined(HAVE_STRTOK_R)
32  return strtok_r(s1, s2, ptr);
33 
34 #elif defined(_MSC_VER) && defined(HAVE_STRTOK_S)
35  return strtok_s(s1, s2, ptr);
36 
37 #else /* SDL implementation */
38 /*
39  * Adapted from _PDCLIB_strtok() of PDClib library at
40  * https://github.com/DevSolar/pdclib.git
41  *
42  * The code was under CC0 license:
43  * https://creativecommons.org/publicdomain/zero/1.0/legalcode :
44  *
45  * No Copyright
46  *
47  * The person who associated a work with this deed has dedicated the
48  * work to the public domain by waiving all of his or her rights to
49  * the work worldwide under copyright law, including all related and
50  * neighboring rights, to the extent allowed by law.
51  *
52  * You can copy, modify, distribute and perform the work, even for
53  * commercial purposes, all without asking permission. See Other
54  * Information below.
55  */
56  const char *p = s2;
57 
58  if (!s2 || !ptr || (!s1 && !*ptr)) return NULL;
59 
60  if (s1 != NULL) { /* new string */
61  *ptr = s1;
62  } else { /* old string continued */
63  if (*ptr == NULL) {
64  /* No old string, no new string, nothing to do */
65  return NULL;
66  }
67  s1 = *ptr;
68  }
69 
70  /* skip leading s2 characters */
71  while (*p && *s1) {
72  if (*s1 == *p) {
73  /* found separator; skip and start over */
74  ++s1;
75  p = s2;
76  continue;
77  }
78  ++p;
79  }
80 
81  if (! *s1) { /* no more to parse */
82  *ptr = s1;
83  return NULL;
84  }
85 
86  /* skipping non-s2 characters */
87  *ptr = s1;
88  while (**ptr) {
89  p = s2;
90  while (*p) {
91  if (**ptr == *p++) {
92  /* found separator; overwrite with '\0', position *ptr, return */
93  *((*ptr)++) = '\0';
94  return s1;
95  }
96  }
97  ++(*ptr);
98  }
99 
100  /* parsed to end of string */
101  return s1;
102 #endif
103 }
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat s1
GLfloat GLfloat p
#define NULL
Definition: begin_code.h:163
set set set set set set set set set set set set set set set set set set set set *set set set macro pixldst op &r &cond WK op &r &cond WK op &r &cond WK else op &m &cond &ia op &r &cond WK else op &m &cond &ia elseif elseif else error unsupported base if elseif elseif else error unsupported unaligned pixldst unaligned endm macro pixst base base else pixldst base endif endm macro PF ptr

References NULL, and ptr.