From 87bce91050b56915dcf5964f6f66d5f47299e7f3 Mon Sep 17 00:00:00 2001 From: Charles Date: Tue, 29 Oct 2019 01:57:41 +0100 Subject: Reworking, binary flags, extract advance - Binary flags attribute instead of multiple bool - Extract doesnst strdup fmt each time, just advance the current pointer - In parsing push front then reverse - Moved some functions to libf --- parse.c | 50 +++++++++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 23 deletions(-) (limited to 'parse.c') diff --git a/parse.c b/parse.c index d486ae7..83a7d55 100644 --- a/parse.c +++ b/parse.c @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* parse.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/29 00:11:33 by cacharle #+# #+# */ +/* Updated: 2019/10/29 00:11:50 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + #include #include "header.h" @@ -7,30 +19,25 @@ ** %(?:\d+\$)?[-]?(?:[0]|'.{1})?-?\d*(?:\.\d+)?[cdusxX] */ -#include -t_flist *parse(const char *format) +t_flist *parse(char *format) { - t_flist *format_list; - t_flist *tmp; - t_pformat *parsed; + t_flist *format_list; + t_flist *tmp; + t_pformat *parsed; format_list = NULL; while (*format) { - if (*format != '%') - { - format++; - continue; - } format++; - if ((parsed = parse_reduced(isolate_conversion(format))) == NULL) + if (format[-1] != '%') + continue; + if ((parsed = parse_reduced(format)) == NULL) return (list_destroy(&format_list)); if ((tmp = list_new(parsed)) == NULL) return (list_destroy(&format_list)); list_push_front(&format_list, tmp); } - list_reverse(&format_list); - return (format_list); + return (list_reverse(format_list)); } t_pformat *parse_reduced(char *fmt) @@ -45,17 +52,14 @@ t_pformat *parse_reduced(char *fmt) return (NULL); if ((pformat = (t_pformat*)malloc(sizeof(t_pformat))) == NULL) return (NULL); - pformat->left_adjusted = FALSE; - pformat->zero_padding = FALSE; - pformat->precision.value = -1; - pformat->precision.wildcard = FALSE; - pformat->min_width.value = -1; - pformat->min_width.wildcard = FALSE; + pformat->precision = -1; + pformat->min_width = -1; + pformat->flags = 0; pformat->len = ft_strlen(fmt); - pformat->conversion = strrchr_index(CONVERSIONS_STR, fmt[pformat->len - 1]); + pformat->conversion = fmt[pformat->len - 1]; fmt[pformat->len - 1] = '\0'; - fmt = extract_standalone_flags(pformat, fmt + i); - fmt = extract_min_width(pformat, fmt + i); - fmt = extract_precision(pformat, fmt + i); + fmt = extract_standalone_flags(pformat, fmt); + fmt = extract_min_width(pformat, fmt); + fmt = extract_precision(pformat, fmt); return (pformat); } -- cgit