-
Notifications
You must be signed in to change notification settings - Fork 0
/
pf_parse_precision.c
45 lines (41 loc) · 1.55 KB
/
pf_parse_precision.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* pf_parse_precision.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gkhodizo <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/07/19 22:12:41 by gkhodizo #+# #+# */
/* Updated: 2020/08/02 10:37:09 by gkhodizo ### ########.fr */
/* */
/* ************************************************************************** */
/*
** The parse_precision() parses precision from str, and uses parse_numeric()
** to find numeric value of precision. If only '.' is set as a precision
** in str, precision value will be set to 0.
** Returns number of chars parsed.
*/
#include "ft_printf.h"
int parse_precision(char *str, t_fmt *fmt, va_list *ap)
{
int i;
ssize_t tmp;
i = 0;
if (str[i] == '.')
{
++i;
fmt->is_precision = 1;
if (str[i] == '*')
{
tmp = va_arg(*ap, int);
fmt->precision = tmp < 0 ? 0 : tmp;
fmt->negative_prec = tmp < 0 ? ft_absolute_val(tmp) : 0;
++i;
}
else if (ft_isdigit(str[i]))
i += parse_numeric((str + i), &fmt->precision);
else
fmt->precision = 0;
}
return (i);
}