diff options
| author | Charles <sircharlesaze@gmail.com> | 2019-10-29 01:57:41 +0100 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2019-10-29 02:02:09 +0100 |
| commit | 87bce91050b56915dcf5964f6f66d5f47299e7f3 (patch) | |
| tree | 8c8fef15ffb962cfa860181ffad3fdd52c71b4f0 /parse.c | |
| parent | f6ee1462e26d723cf5d53157eadaff2804d18c3a (diff) | |
| download | ft_printf-87bce91050b56915dcf5964f6f66d5f47299e7f3.tar.gz ft_printf-87bce91050b56915dcf5964f6f66d5f47299e7f3.tar.bz2 ft_printf-87bce91050b56915dcf5964f6f66d5f47299e7f3.zip | |
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
Diffstat (limited to 'parse.c')
| -rw-r--r-- | parse.c | 50 |
1 files changed, 27 insertions, 23 deletions
@@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* parse.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/29 00:11:33 by cacharle #+# #+# */ +/* Updated: 2019/10/29 00:11:50 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + #include <stdlib.h> #include "header.h" @@ -7,30 +19,25 @@ ** %(?:\d+\$)?[-]?(?:[0]|'.{1})?-?\d*(?:\.\d+)?[cdusxX] */ -#include <stdio.h> -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); } |
