/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_printf_utils2.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: jguelen +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/12/05 17:10:15 by jguelen #+# #+# */ /* Updated: 2024/12/11 14:23:21 by jguelen ### ########.fr */ /* */ /* ************************************************************************** */ #include "ft_printf.h" int ft_isnumeric_conv(t_printf_format *format) { t_printf_spec spec; spec = format->specifier; if (spec == PRINTF_HEXA_LOWSPEC || spec == PRINTF_HEXA_UPSPEC || spec == PRINTF_INTSPEC || spec == PRINTF_UINTSPEC) return (1); return (0); } static void get_prefix_format_util(t_printf_format *format) { t_printf_spec spec; spec = format->specifier; if (ft_isnumeric_conv(format) && (format->flags & PRINTF_DOTFLAG)) format->flags &= ~PRINTF_ZEROFLAG; if (spec == PRINTF_POINTERSPEC) { ft_strlcpy(format->prefix, HEXA_RADIX_LOW, 3); format->prefix_len = 2; } if (spec == PRINTF_INTSPEC || (spec == PRINTF_POINTERSPEC && format->var.p) || ((spec == PRINTF_HEXA_LOWSPEC || spec == PRINTF_HEXA_UPSPEC) && format->var.u)) format->total_len += format->prefix_len; } void get_prefix_format(t_printf_format *format) { if ((format->flags & PRINTF_PLUSFLAG) && format->specifier == PRINTF_INTSPEC && format->var.i >= 0) { format->flags &= ~PRINTF_SPACEFLAG; format->prefix[0] = '+'; format->prefix_len = 1; } else if ((format->flags & PRINTF_HASHTAGFLAG) && (format->specifier == PRINTF_HEXA_LOWSPEC || format->specifier == PRINTF_HEXA_UPSPEC) && format->var.u != 0) { ft_strlcpy(format->prefix, HEXA_RADIX_LOW, 3); if (format->specifier == PRINTF_HEXA_UPSPEC) ft_strlcpy(format->prefix, HEXA_RADIX_UP, 3); format->prefix_len = 2; } else if ((format->flags & PRINTF_SPACEFLAG) && format->specifier == PRINTF_INTSPEC && format->var.i >= 0) { format->prefix[0] = ' '; format->prefix_len = 1; } get_prefix_format_util(format); }