/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/09/05 11:28:21 by ljiriste #+# #+# */
-/* Updated: 2023/09/15 15:33:50 by ljiriste ### ########.fr */
+/* Updated: 2023/09/27 17:01:46 by ljiriste ### ########.fr */
/* */
/* ************************************************************************** */
free (*str);
*str = ft_strdup("(nil)");
}
- else if (conv.type == 's' && *str == NULL)
+ else if (conv.type == 's' && *str == NULL
+ && (conv.prec >= 6 || conv.prec < 0))
*str = ft_strdup("(null)");
+ else if (conv.type == 's' && *str == NULL)
+ *str = ft_strdup("");
init_printed(&res);
create_main(*str, &res, conv);
create_alt(&res, conv);
/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/09/05 11:25:46 by ljiriste #+# #+# */
-/* Updated: 2023/09/27 15:16:21 by ljiriste ### ########.fr */
+/* Updated: 2023/09/27 16:48:26 by ljiriste ### ########.fr */
/* */
/* ************************************************************************** */
return ;
}
-void create_padding(t_to_print *tp, t_conv conv)
+void create_padding(t_to_print *tp, t_conv cv)
{
size_t len;
- len = ft_strlen(tp->main_part) + (!tp->main_part[0] && conv.type == 'c');
- if (conv.type == 's' || conv.type == 'c')
+ len = ft_strlen(tp->main_part) + (!tp->main_part[0] && cv.type == 'c');
+ if (cv.type == 's' || cv.type == 'c')
tp->zero_pad = ft_strdup("");
else
- tp->zero_pad = repeat_char('0', conv.prec - len);
+ tp->zero_pad = repeat_char('0', cv.prec - len);
len += ft_strlen(tp->zero_pad) + ft_strlen(tp->alt) + (tp->sign != '\0');
- if (conv.flags.left_adjust)
+ if (cv.flags.left_adjust)
{
- tp->right_pad = repeat_char(' ', conv.minwidth - len);
+ tp->right_pad = repeat_char(' ', cv.minwidth - len);
tp->left_pad = ft_strdup("");
}
else
{
tp->right_pad = ft_strdup("");
- if (!conv.flags.zero_pad || conv.type == 's' || conv.type == 'c')
- tp->left_pad = repeat_char(' ', conv.minwidth - len);
- else if (conv.flags.zero_pad)
+ if (cv.flags.zero_pad && cv.prec < 0 && ft_strchr("diouxX", cv.type))
{
tp->left_pad = ft_strdup("");
- lengthen_by_zeros(&(tp->zero_pad), conv.minwidth - len);
+ lengthen_by_zeros(&(tp->zero_pad), cv.minwidth - len);
}
+ else
+ tp->left_pad = repeat_char(' ', cv.minwidth - len);
}
return ;
}