/* By: agilliar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */
JUSTIFY_RIGHT,
} t_justify;
-typedef enum e_padding_type
-{
- PADDING_SPACE,
- PADDING_ZEROS,
-} t_padding_type;
-
typedef enum e_specifier
{
SPECIFIER_NONE,
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;
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);
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);
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;
ft_parse_width(s, &res);
ft_parse_precision(s, &res);
res.specifier = ft_parse_specifier(*((*s)++));
+ ft_format_normalize(&res);
return (res);
}
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);
}