-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_printf_parse.c
More file actions
78 lines (71 loc) · 2.06 KB
/
Copy pathft_printf_parse.c
File metadata and controls
78 lines (71 loc) · 2.06 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf_parse.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kgricour <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/02/16 17:33:45 by kgricour #+# #+# */
/* Updated: 2018/03/06 23:28:07 by kgricour ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
char *ft_get_opt(char *s)
{
char *opt;
int i;
int k;
const char *flags;
flags = "#-+jz hl.*";
i = 1;
k = 1;
while (s[i])
{
if (ft_strchr(flags, s[i]) || ft_isdigit(s[i]))
i++;
else
break ;
}
i++;
opt = ft_strnew(i);
while (k < i)
{
opt[k - 1] = s[k];
k++;
}
return (opt);
}
int ft_check_valide_conv(char *s, int *j)
{
const char *format;
const char *flags;
format = "scSbpdDioOuUXxC%";
flags = "#-+jz hl.*";
while (s[*j])
{
if (ft_strchr(format, s[*j]))
return (1);
else if (ft_strchr(flags, s[*j]) || ft_isdigit(s[*j]))
*j += 1;
else
return (0);
}
return (0);
}
char *ft_find_conv(char *new_str, int *i, va_list vl)
{
char *opt;
opt = ft_get_opt(new_str + *i);
if (ft_strchrstr("%", opt, '&'))
*i += ft_printf_pct(&new_str, opt, *i);
else if (ft_strchrstr("sS", opt, '|'))
*i += ft_printf_s(&new_str, *i, vl, opt);
else if (ft_strchrstr("cC", opt, '|'))
*i += ft_printf_c(&new_str, *i, vl, opt);
else if (ft_strchrstr("dDi", opt, '|'))
*i += ft_printf_id(&new_str, *i, vl, opt);
else if (ft_strchrstr("XxOoUubp", opt, '|'))
*i += ft_printf_xobup(&new_str, *i, vl, opt);
ft_strdel(&opt);
return (new_str);
}