en cours de flag espace

This commit is contained in:
Hugo LAMY
2020-03-10 17:45:13 +01:00
parent d2f5890fe1
commit 01aab8912c
7 changed files with 180 additions and 12 deletions

View File

@@ -108,15 +108,12 @@ char *width_flags(char *print, char *s, int width, int zero)
}
else
{
// c = (ft_strchr(s, '0')) ? '0' : ' ';
// ft_memset(tmp, c, width - len);
ft_memset(tmp, (ft_strchr(s, '0')) ? '0' : ' ', width - len);
ft_memmove(ft_strchr(tmp, '\0') + zero, print, ft_strlen(print));
// if (c == '0' && (minus = ft_strchr(tmp, '-')))
if (ft_strchr(s, '0') && (minus = ft_strchr(tmp, '-')))
if (ft_strchr(s, '0') && (minus = ft_strchrset("+-", tmp)))
{
tmp[0] = (minus[0] == '+') ? '+' : '-';
minus[0] = '0';
tmp[0] = '-';
}
}
free(print);
@@ -167,13 +164,21 @@ char *ft_width(char *s, char *print, int *size, char *type)
/*
** -go through all the transformation flags needs
** -first the precision
** -then if type is int and nbr is positive, add a + to the left, it's flag '+'
** -third the flag "#"
** -fourth, the width
** -then p
** -the case of 'p' is treated without any subtelness because i don't care
*/
char *ft_flag_transform(char *s, char *print, char *type, int *size)
{
print = ft_precision(s, print, type);
print = ft_plus(s, print, type);
print = ft_sharp(s, print, type);
print = ft_width(s, print, size, type);
print = ft_sharp_again(s, print, type);
if (ft_strchr(type, 'p'))
{
print = ft_concat_free(ft_strdup("0x"), print);

View File

@@ -0,0 +1,39 @@
#include "ft_printf.h"
char *ft_plus(char *s, char *print, char *type)
{
if (!ft_strchrset(type, "di"))
return (print);
if (ft_strchr(s, '+') && !ft_strchr(print, '-'))
print = ft_concat_free(ft_strdup("+"), print);
return (print);
}
char *ft_sharp(char *s, char *print, char *type)
{
if (ft_strchr(s, '#'))
{
if (ft_strchr(type, 'x'))
print = ft_concat_free(ft_strdup("0x"), print);
else
print = ft_concat_free(ft_strdup("0X"), print);
}
return (print);
}
char *ft_sharp_again(char *s, char *print, char *type)
{
char *tmp;
if (!ft_strchr(s, '#'))
return (print);
if (print[0] == '0' && print[1] == '0' && ft_strchrset(type, "xX"))
{
tmp = ft_strchrset("xX", print);
print[1] = tmp[0];
tmp[0] = '0';
}
return (print);
}