-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtype_s.c
More file actions
63 lines (59 loc) · 1.98 KB
/
type_s.c
File metadata and controls
63 lines (59 loc) · 1.98 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* type_s.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vvarodi <vvarodi@student.42madrid.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/08/14 01:13:34 by vvarodi #+# #+# */
/* Updated: 2020/08/19 00:30:12 by vvarodi ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
char *type_s_left(t_buffer *b, t_flags *f, char *print, char *str)
{
if (f->b_preci == 0)
{
while (*print != '\0')
add_to_buffer(b, f, *print++);
}
else
{
if (f->precision < 0)
{
while (*print && f->precision++ < 0)
add_to_buffer(b, f, *print++);
}
while (*print && f->precision-- > 0)
add_to_buffer(b, f, *print++);
}
while (f->width > 0)
f->b_zero_padding == 1 ? add_to_buffer(b, f, '0') :
add_to_buffer(b, f, ' ');
return (str);
}
char *type_s(t_buffer *b, t_flags *f, char *print, char *str)
{
int length;
if (print == NULL)
print = "(null)";
length = ft_strlen(print);
if (f->b_left_aligned == 1)
return (type_s_left(b, f, print, str));
if (f->precision == 0)
{
f->to_write = ft_strlen(print);
if (f->b_preci == 2)
f->to_write = 0;
}
else if (f->precision < 0)
f->to_write = length;
else
f->to_write = length < f->precision ? length : f->precision;
while (f->width > f->to_write)
f->b_zero_padding == 1 ? add_to_buffer(b, f, '0') :
add_to_buffer(b, f, ' ');
while (f->to_write-- > 0)
add_to_buffer(b, f, *print++);
return (str);
}