aboutsummaryrefslogtreecommitdiff
path: root/extract.c
blob: 7054c381dacb0480f0c8ef3cb35e93c991772413 (plain)
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
#include <stdlib.h>
#include "header.h"

char	*extract_standalone_flags(t_pformat *pformat, char *fmt)
{
	int		i;

	i = 0;
	while (IS_STANDALONE_FLAG(fmt[i]))
	{
		if (!pformat->zero_padding)
			pformat->zero_padding = fmt[i] == '0';
		if (!pformat->left_adjusted)
			pformat->left_adjusted = fmt[i] == '-';
		i++;
	}
 	return (fmt + i);
}

char	*extract_min_width(t_pformat *pformat, char *fmt)
{
	int		i;
	int		tmp;

	i = 0;
	if (*fmt == '*')
	{
		pformat->min_width.wildcard = TRUE;
		i++;
	}
	else
	{
		if (ft_isdigit(fmt[i]))
		{
			tmp = ft_atoi(&fmt[i]);
			while (ft_isdigit(fmt[i]))
				i++;
			pformat->min_width.value = tmp;
			pformat->min_width.wildcard = FALSE;
		}
	}
	return (fmt + i);
}

char	*extract_precision(t_pformat *pformat, char *fmt)
{
	int		i;
	int		tmp;

	if (*fmt != '.')
		return (fmt);
	i = 1;
	if (fmt[i] == '*')
	{
		pformat->precision.wildcard = TRUE;
		i++;
	}
	else if (!ft_isdigit(fmt[i]))
		pformat->precision.value = 0;
	tmp = ft_atoi(&fmt[i]);
	while (ft_isdigit(fmt[i]))
		i++;
	pformat->precision.value = tmp;
	return (fmt + i);
}