-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_printf5.c
99 lines (92 loc) · 2.75 KB
/
ft_printf5.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
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf5.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: plisieck <plisieck@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/02/07 21:18:44 by plisieck #+# #+# */
/* Updated: 2015/02/07 21:30:00 by plisieck ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
char *treat_largeur2(char *str, t_specs opt, char c, int *tab)
{
while (ft_strlen(str) + tab[4] < (unsigned int)opt.largeur)
{
if (tab[0] && opt.largeur == -1)
opt.precision -= 1;
if (opt.flags & 0x08 && (opt.precision != 0 ||
!(verif_str("dDxXiuUoO", c))))
{
if (opt.precision <= 0 || verif_str("cCsS", c))
str = ft_strjoin("0", str);
else
str = ft_strjoin(" ", str);
if (str[0] == '-')
tab[0] = 1;
}
else
{
if (!(opt.flags & 0x04))
str = ft_strjoin(" ", str);
else
str = ft_strjoin(str, " ");
}
}
return (str);
}
char *treat_largeur3(char *str, t_specs opt, int *tab)
{
if (opt.flags & 0x08 && (tab[0] || tab[1] || tab[3]))
{
if (tab[0])
str = ft_strjoin("-", str);
if (tab[3])
str[1] = 'x';
if (tab[1])
str[0] = ' ';
}
return (str);
}
char *treat_largeur(char *str, t_specs opt, char c, int z)
{
int *tab;
if (ft_strlen(str) > (unsigned int)opt.largeur)
return (str);
tab = init_tab();
if (opt.flags & 0x08 && opt.precision == -1 &&
(str[0] == '-' || str[0] == ' ' ||
str[0] == '+' || str[1] == 'x'))
{
tab = asign_tab(tab, opt, str);
if (str[1] != 'x')
str++;
}
if (tab[0])
opt.largeur -= 1;
tab[4] = z;
str = treat_largeur2(str, opt, c, tab);
if (tab[2] == 1)
str[0] = '+';
str = treat_largeur3(str, opt, tab);
return (str);
}
char *treat_flag_space(char *str, t_specs opt, char c)
{
if (c != 'd' && c != 'D' && c != 'i')
return (str);
if (str[0] != '-' && opt.flags & 0x01)
str = ft_strjoin(" ", str);
return (str);
}
wchar_t *wtreat_precision(wchar_t *wstr, t_specs opt, char c)
{
if (opt.precision == -1 || c == 'C')
return (wstr);
if (c != 'c' && (unsigned int)opt.precision < ft_wstrlen(wstr))
wstr = ft_wstrsub(wstr, 0, opt.precision);
if (c == 'S' && (unsigned int)opt.precision < ft_wstrlen(wstr))
wstr = ft_wstrsub(wstr, 0, opt.precision);
return (wstr);
}