-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_split_printf.c
More file actions
111 lines (100 loc) · 2.28 KB
/
ft_split_printf.c
File metadata and controls
111 lines (100 loc) · 2.28 KB
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
103
104
105
106
107
108
109
110
111
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_split_printf.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mifernan <mifernan@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/11/13 13:41:01 by mifernan #+# #+# */
/* Updated: 2019/11/29 10:40:45 by mifernan ### ########.fr */
/* */
/* ************************************************************************** */
#include "libftprintf.h"
void ft_free_tab(char **tab)
{
int i;
i = 0;
if (tab)
{
while (tab[i])
{
ft_strdel(&tab[i]);
i++;
}
free(tab);
}
}
int ft_end_conv(char c)
{
char *conv;
int i;
conv = ft_strdup("-0123456789.*");
i = 0;
while (conv[i])
{
if (c == conv[i])
{
ft_strdel(&conv);
return (1);
}
i++;
}
ft_strdel(&conv);
return (0);
}
int ft_is_conv(char c)
{
char *conv;
int i;
conv = ft_strdup("cspdiuxX-0123456789.*");
i = 0;
while (conv[i])
{
if (c == conv[i])
{
ft_strdel(&conv);
return (1);
}
i++;
}
ft_strdel(&conv);
return (0);
}
char *ft_find_flags(const char *str)
{
int i;
char *cpy;
cpy = NULL;
i = 0;
while (str[i])
{
if ((i != 0) && (str[i - 1] == '%'))
{
cpy = ft_strjoin_free(cpy, ft_convert_char(str[i - 1]), 3);
if (str[i] == '%')
cpy = ft_strjoin_free(cpy, ft_convert_char(str[i++]), 3);
else
{
while ((ft_end_conv(str[i]) == 1) && str[i])
cpy = ft_strjoin_free(cpy, ft_convert_char(str[i++]), 3);
if (ft_is_conv(str[i]) == 1)
cpy = ft_strjoin_free(cpy, ft_convert_char(str[i++]), 3);
}
cpy = ft_strjoin_free(cpy, ft_convert_char(','), 3);
}
i++;
}
cpy = ft_strjoin_free(cpy, ft_convert_char('\0'), 3);
return (cpy);
}
char **ft_split_flags(const char *str)
{
char **tab;
char *s;
int i;
i = 0;
s = ft_find_flags(str);
tab = ft_split(s, ',');
ft_strdel(&s);
return (tab);
}