61 lines
1.8 KiB
C
61 lines
1.8 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ft_ui_case.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: pbonilla <eirodeis.lepnj@gmail.com> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2021/03/08 06:18:38 by pbonilla #+# #+# */
|
|
/* Updated: 2021/03/20 20:18:26 by pbonilla ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "../includes/ft_printf.h"
|
|
|
|
char *fill_s_uint(char *s, int len, char *s_ui, t_param *param)
|
|
{
|
|
int save;
|
|
int i;
|
|
|
|
save = ft_strlen(s_ui);
|
|
i = save;
|
|
while (--len >= 0 && --i >= 0)
|
|
{
|
|
s[len] = s_ui[i];
|
|
if (s_ui[0] == '0' && param->prec == 0)
|
|
s[len] = ' ';
|
|
}
|
|
while (param->prec-- > save)
|
|
s[len--] = '0';
|
|
return (s);
|
|
}
|
|
|
|
char *ft_ui_case(t_param *param, unsigned int i)
|
|
{
|
|
int save;
|
|
int len;
|
|
char *s_ui;
|
|
char *s;
|
|
|
|
if (param->prec != -1 && param->zero)
|
|
param->zero = 0;
|
|
s_ui = ft_u_itoa(i);
|
|
len = ft_strlen(s_ui);
|
|
if (i == 0 && param->prec == 0)
|
|
len = 0;
|
|
if (param->prec > len)
|
|
len = param->prec;
|
|
save = len;
|
|
if (param->width > len)
|
|
len = param->width;
|
|
if (!(s = malloc(sizeof(char) * (len + 1))))
|
|
return (NULL);
|
|
s[len] = 0;
|
|
ft_printf_memset(s, len, param);
|
|
if (param->minus)
|
|
len = save;
|
|
s = fill_s_uint(s, len, s_ui, param);
|
|
free(s_ui);
|
|
return (s);
|
|
}
|