-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_color.c
54 lines (49 loc) · 1.39 KB
/
ft_color.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_color.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aelsayed <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/08 16:43:44 by kali #+# #+# */
/* Updated: 2025/02/10 13:29:54 by aelsayed ### ########.fr */
/* */
/* ************************************************************************** */
#include "fdf.h"
int is_valid(const char c)
{
char *str;
int i;
i = 0;
str = "0123456789abcdef";
while (str[i])
{
if (c == str[i])
return (i);
i++;
}
return (-1);
}
int ft_color(const char *s)
{
int i;
int color;
color = 0;
i = 0;
if (!s)
return (0);
while (s[i] != ',' && s[i])
i++;
if (!s[i])
return (0xffffff);
i++;
if (s[i] == '0' && s[i + 1] == 'x')
{
i += 2;
while (s[i] && is_valid(s[i]) != -1)
color = (color * 16) + is_valid(s[i++]);
return (color);
}
else
return (0xffffff);
}