-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper_str3.c
99 lines (89 loc) · 1.78 KB
/
helper_str3.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include "shell.h"
/**
* _strstr_int - finds the first occurence of the substring needle
* in the string haystack
* @haystack: string to search
* @needle: string to find
* Return: index to the beginning of the located substring
*/
int _strstr_int(char *haystack, char *needle)
{
int i;
i = 0;
while (*haystack != '\0')
{
char *beginning = haystack;
char *pattern = needle;
while (*pattern == *haystack && *pattern != '\0'
&& *haystack != '\0')
{
haystack++;
pattern++;
}
if (*pattern == '\0')
return (i);
haystack = beginning + 1;
i++;
}
return (-1);
}
/**
* _strpbrk_int - Finds and returns index of first char needle in string
* @s: haystack to search
* @needles: Chars to search for in s
* Return: index of first char in s, else -1
*/
int _strpbrk_int(char *s, char *needles)
{
int i, c;
for (i = 0; s[i]; i++)
for (c = 0; needles[c]; c++)
if (needles[c] == s[i])
return (i);
return (-1);
}
/**
* _str_match_strict - See if two strings are matching
* @s1: string 1
* @s2: string 2
* Description: Returns a match if both strings are the exactly the same
*
* Return: 1 if match, 0 if not match
*/
int _str_match_strict(char *s1, char *s2)
{
int i;
if (s1 == NULL || s2 == NULL)
return (0);
for (i = 0; s1[i] == s2[i]; i++)
{
if (s1[i] == '\0' || s2[i] == '\0')
return (1);
}
return (0);
}
/**
* is_alpha - checks whether or not a char is alpha
* @c: character to check
* Return: 1 if true, 0 if false
*/
int is_alpha(char c)
{
if (c >= 'a' && c <= 'z')
return (1);
else if (c >= 'A' && c <= 'Z')
return (1);
else
return (0);
}
/**
* is_digit - checks whether something is a digit
* @c: character to check
* Return: 1 if true, 0 if false
*/
int is_digit(char c)
{
if (c >= '0' && c <= '9')
return (1);
return (0);
}