From: = <=> Date: Thu, 30 Oct 2025 17:05:32 +0000 (+0100) Subject: Extra flag compliance X-Git-Tag: Testable~8 X-Git-Url: https://git.uwuaxy.net/?a=commitdiff_plain;h=b64e077532d0b3d8d28d1c2690a3564e403022e6;p=axy%2Fft%2Fft_printf.git Extra flag compliance --- diff --git a/ft_printf.c b/ft_printf.c index d2817f5..415463b 100644 --- a/ft_printf.c +++ b/ft_printf.c @@ -6,7 +6,7 @@ /* By: agilliar +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/10/29 14:24:47 by agilliar #+# #+# */ -/* Updated: 2025/10/30 17:42:47 by agilliar ### ########.fr */ +/* Updated: 2025/10/30 18:00:09 by agilliar ### ########.fr */ /* */ /* ************************************************************************** */ @@ -49,12 +49,6 @@ typedef enum e_justify JUSTIFY_RIGHT, } t_justify; -typedef enum e_padding_type -{ - PADDING_SPACE, - PADDING_ZEROS, -} t_padding_type; - typedef enum e_specifier { SPECIFIER_NONE, @@ -81,7 +75,7 @@ typedef struct s_format t_justify justify; t_num_prefix num_prefix; int width; - t_padding_type padding_type; + bool zero_pad; int precision; bool enable_precision; } t_format; @@ -168,7 +162,7 @@ t_format ft_format_default(void) res.justify = JUSTIFY_RIGHT; res.num_prefix = NUM_PREFIX_NONE; res.width = 0; - res.padding_type = PADDING_SPACE; + res.zero_pad = false; res.precision = 0; res.enable_precision = false; return (res); @@ -199,7 +193,7 @@ bool ft_parse_flag(char c, t_format *format) else if (c == '#') format->num_prefix = NUM_PREFIX_FORMAT; else if (c == '0') - format->padding_type = PADDING_ZEROS; + format->zero_pad = true; else return (false); return (true); @@ -246,6 +240,12 @@ t_specifier ft_parse_specifier(char c) return (SPECIFIER_NONE); } +void ft_format_normalize(t_format *format) +{ + if (format->justify == JUSTIFY_LEFT) + format->zero_pad = false; +} + t_format ft_parse_format(const char **s) { t_format res; @@ -256,6 +256,7 @@ t_format ft_parse_format(const char **s) ft_parse_width(s, &res); ft_parse_precision(s, &res); res.specifier = ft_parse_specifier(*((*s)++)); + ft_format_normalize(&res); return (res); } @@ -320,6 +321,6 @@ int ft_printf(const char *s, ...) int main(void) { const char *s = "hai"; - ft_printf("c%-10.2s", s); - printf("c%-10.2s", s); + ft_printf("c%-10p", s); + printf("c%-10p", s); }