-
Notifications
You must be signed in to change notification settings - Fork 0
/
set_zero_minwidth_minus_prec.c
55 lines (50 loc) · 1.7 KB
/
set_zero_minwidth_minus_prec.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* set_zero_minwidth_minus_prec.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: monoue <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/08/06 16:09:36 by monoue #+# #+# */
/* Updated: 2020/08/24 09:30:00 by monoue ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
static int minwidth_o_prec_to_int(char *target, int *index)
{
int num;
num = 0;
while (ft_isdigit(target[*index]))
{
num = num * 10 + CTOI(target[*index]);
(*index)++;
}
return (num);
}
static void get_index_when_prec_invalid(char *target, int *index)
{
(*index)++;
while (ft_isdigit(target[*index]))
(*index)++;
}
void set_zero_minwidth_minus_prec(char *target, int *index,
t_format_info *info)
{
if (target[*index] == '0')
info->zero = true;
if (ft_isdigit(target[*index]))
info->min_width = minwidth_o_prec_to_int(target, index);
if (target[*index] == '-')
{
info->minus = true;
(*index)++;
}
if (target[*index] == '.')
{
(*index)++;
if (target[*index] == '-')
get_index_when_prec_invalid(target, index);
else
info->precision = minwidth_o_prec_to_int(target, index);
}
}