-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalid_utils.c
102 lines (93 loc) · 2.1 KB
/
valid_utils.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
100
101
102
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* valid_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: shongou <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/04 23:34:47 by shongou #+# #+# */
/* Updated: 2023/01/04 23:34:48 by shongou ### ########.fr */
/* */
/* ************************************************************************** */
#include "minirt.h"
bool valid_float(char *str)
{
bool dot_flag;
size_t i;
if (!str)
return (false);
dot_flag = false;
i = 0;
if (str[i] == '-' || str[i] == '+')
i++;
while (str[i] && ft_isdigit(str[i]))
{
i++;
if (!dot_flag && str[i] == '.')
{
i++;
dot_flag = true;
}
}
if (str[i] == '\0')
return (true);
return (false);
}
bool valid_vector(char *str)
{
size_t i;
char **split_str;
split_str = ft_split(str, ',');
if (!split_str || !(*split_str))
return (false);
i = 0;
while (split_str[i])
{
if (!valid_float(split_str[i]))
{
free_strs(split_str);
return (false);
}
i++;
}
free_strs(split_str);
if (i == 3)
return (true);
return (false);
}
bool valid_digit(char *str)
{
size_t i;
i = 0;
if (str[i] == '-' || str[i] == '+')
i++;
while (str[i] && ft_isdigit(str[i]))
{
i++;
}
if (str[i] == '\0')
return (true);
return (false);
}
bool valid_color(char *str)
{
size_t i;
char **split_str;
split_str = ft_split(str, ',');
if (!split_str || !(*split_str))
return (false);
i = 0;
while (split_str[i])
{
if (!valid_float(split_str[i]))
{
free_strs(split_str);
return (false);
}
i++;
}
free_strs(split_str);
if (i == 3)
return (true);
return (false);
}