-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_flags.c
73 lines (64 loc) · 1.37 KB
/
get_flags.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
/*
** EPITECH PROJECT, 2023
** get_flags
** File description:
** Placeholder
*/
#include <stdio.h>
#include "include/my.h"
int is_flag(char c)
{
return (c == ' ' || c == '#' || c == '0' || c == '-' || c == '+');
}
static int contains_hashtag(const char *restrict str)
{
for (int i = 0; is_flag(str[i]); i++) {
if (str[i] == '#')
return 1;
}
return 0;
}
static int contains_space(const char *restrict str)
{
for (int i = 0; is_flag(str[i]); i++) {
if (str[i] == ' ')
return 1;
}
return 0;
}
static int contains_plus(const char *restrict str)
{
for (int i = 0; is_flag(str[i]); i++) {
if (str[i] == '+')
return 1;
}
return 0;
}
static int contains_minus(const char *restrict str)
{
for (int i = 0; is_flag(str[i]); i++) {
if (str[i] == '-')
return 1;
}
return 0;
}
static int contains_zero(const char *restrict str)
{
for (int i = 0; is_flag(str[i]); i++) {
if (str[i] == '0')
return 1;
}
return 0;
}
int get_flags(const char *restrict str)
{
int ret = 0;
int (*contains_char[5])(const char *restrict) = {&contains_minus,
&contains_zero,
&contains_hashtag, &contains_space, &contains_plus};
for (int i = 0; i < 5; i++) {
ret = ret << 1;
ret += contains_char[i](str);
}
return ret;
}