-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strlen.c
55 lines (50 loc) · 1.63 KB
/
ft_strlen.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlen.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: johnavar <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/05/02 11:46:33 by johnavar #+# #+# */
/* Updated: 2024/02/05 20:50:53 by sebasnadu ### ########.fr */
/* */
/* ************************************************************************** */
#include "../../include/libft.h"
inline static int longchr_null(unsigned long c)
{
return (((c - 0x0101010101010101) & 0x8080808080808080) != 0);
}
inline static size_t ifreturn(const char *cp, const char *s)
{
if (cp[0] == 0)
return ((cp - s));
if (cp[1] == 0)
return ((cp - s) + 1);
if (cp[2] == 0)
return ((cp - s) + 2);
if (cp[3] == 0)
return ((cp - s) + 3);
if (cp[4] == 0)
return ((cp - s) + 4);
if (cp[5] == 0)
return ((cp - s) + 5);
if (cp[6] == 0)
return ((cp - s) + 6);
return ((cp - s) + 7);
}
size_t ft_strlen(const char *s)
{
const unsigned long *str;
const char *cp;
str = (unsigned long *)s;
while (42)
{
if (longchr_null(*str))
{
cp = (const char *)(str);
return (ifreturn(cp, s));
}
++str;
}
return (0);
}