-
Notifications
You must be signed in to change notification settings - Fork 0
/
strings2.c
82 lines (73 loc) · 1.16 KB
/
strings2.c
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include "shellhead.h"
/**
* _strspn - Gets the length of a prefix substring
* @s: Initial segment to get length
* @accept: the bytes to check for
* Return: Number of bytes in s containing bytes from accept
*/
unsigned int _strspn(char *s, const char *accept)
{
unsigned int i, j = 0, k = 0, l;
while (s[j] != '\0')
{
j++;
}
while (accept[k] != '\0')
{
k++;
}
for (i = 0; i < j; i++)
{
for (l = 0; l < k; l++)
{
if (s[i] == accept[l])
break;
}
if (l == k)
break;
}
return (i);
}
/**
* _strcspn - Copy of strcspn
* @s1: First string
* @s2: Second string
* Return: Num
*/
size_t _strcspn(const char *s1, const char *s2)
{
const char *s = s1;
const char *c;
while (*s1)
{
for (c = s2; *c; c++)
{
if (*s1 == *c)
break;
}
if (*c)
break;
s1++;
}
return (s1 - s);
}
/**
* _strtok - Copy of strtok
* @str: Str to tokenize
* @delim: Delimter
* Return: Pointer to token
*/
char *_strtok(char *str, const char *delim)
{
static char *p;
if (str)
p = str;
else if (!p)
return (0);
str = p + _strspn(p, delim);
p = str + _strcspn(str, delim);
if (p == str)
return (p = 0);
p = *p ? *p = 0, p + 1 : 0;
return (str);
}