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

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

	if (!ft_isdigit(*fmt) || *fmt == '0')
		return (fmt);
	tmp = ft_atoi(fmt);
	i = 0;
	while (ft_isdigit(fmt[i]))
		i++;
	if (fmt[i] == '$')
	{
		pformat->ap_index = tmp;
		fmt_dup = ft_strdup(&fmt[++i]);
		free(fmt);
		return (fmt_dup);
	}
	return (fmt);
}

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

	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++;
	}
	fmt_dup = ft_strdup(&fmt[i]);
	free(fmt);
 	return (fmt_dup);
}

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


	i = 0;
	/* if (*fmt == '*') */
	/* { */
	/* 	pformat->min_width.wildcard.exist = TRUE; */
	/* 	i++; */
	/* } */
	if (ft_isdigit(fmt[i]))
	{
		tmp = ft_atoi(&fmt[i]);
		while (ft_isdigit(fmt[i]))
			i++;
		/* printf("%d\n", tmp); */
		/* if (fmt[i] == '$') */
		/* 	pformat->min_width.wildcard.ap_index = tmp; */
		/* else */
		/* { */
			pformat->min_width.hardcoded = tmp;
			pformat->min_width.wildcard.exist = FALSE;
		/* } */
	}
	fmt_dup = ft_strdup(&fmt[i]);
	free(fmt);
	return (fmt_dup);
}

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

	if (*fmt != '.')
		return (fmt);
	i = 1;
	/* if (fmt[i] == '*') */
	/* { */
	/* 	pformat->precision.wildcard.exist = TRUE; */
	/* 	i++; */
	/* } */
	/* else if (!ft_isdigit(fmt[i])) */
	/* 	pformat->precision.hardcoded = 0; */
	tmp = ft_atoi(&fmt[i]);
	while (ft_isdigit(fmt[i]))
		i++;
	/* if (pformat->precision.wildcard.exist && fmt[i] == '$') */
	/* 	pformat->precision.wildcard.ap_index = tmp; */
	/* else */
		pformat->precision.hardcoded = tmp;
	fmt_dup = ft_strdup(&fmt[i]);
	free(fmt);
	return (fmt);
}