diff options
| author | Charles <sircharlesaze@gmail.com> | 2019-11-06 00:02:56 +0100 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2019-11-06 00:02:56 +0100 |
| commit | dafee6410a4ecd7400a83adf84ded3621f30a365 (patch) | |
| tree | 401c4169f4c2bf849d33a6a0201ab47d0f0f7782 /parse.c | |
| parent | e6d8f543af4c1a45f30495b90a3912b1c75f2be7 (diff) | |
| download | ft_printf-dafee6410a4ecd7400a83adf84ded3621f30a365.tar.gz ft_printf-dafee6410a4ecd7400a83adf84ded3621f30a365.tar.bz2 ft_printf-dafee6410a4ecd7400a83adf84ded3621f30a365.zip | |
Refactored parsing to handle alone '%'
- renamed a few variables
- added join_free* to libft
- normed everything but ft_printf.c
Diffstat (limited to 'parse.c')
| -rw-r--r-- | parse.c | 37 |
1 files changed, 14 insertions, 23 deletions
@@ -6,19 +6,12 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/10/29 00:11:33 by cacharle #+# #+# */ -/* Updated: 2019/10/31 00:08:04 by cacharle ### ########.fr */ +/* Updated: 2019/11/05 23:46:02 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ -#include <stdlib.h> #include "header.h" -#define STRRCHR_CONVERSIONS(c) (ft_strrchr(CONVERSIONS_STR, c)) - -/* -** %(?:\d+\$)?[-]?(?:[0]|'.{1})?-?\d*(?:\.\d+)?[cdusxX] -*/ - int parse(char *format, t_flist **flist) { t_flist *tmp; @@ -44,27 +37,25 @@ int parse(char *format, t_flist **flist) t_pformat *parse_reduced(char *fmt) { t_pformat *pformat; - int i; char *start; - i = 0; - while (strrchr_index(CONVERSIONS_STR, fmt[i]) == -1) - i++; - if ((start = ft_strndup(fmt, i + 1)) == NULL) - return (NULL); if ((pformat = (t_pformat*)malloc(sizeof(t_pformat))) == NULL) return (NULL); - fmt = start; pformat->precision = -1; - pformat->min_width = -1; + pformat->width = -1; pformat->flags = 0; - pformat->fmt_len = ft_strlen(fmt); - pformat->type = fmt[pformat->fmt_len - 1]; - fmt[pformat->fmt_len - 1] = '\0'; - fmt = extract_standalone_flags(pformat, fmt); - fmt = extract_min_width(pformat, fmt); + start = fmt; + fmt = extract_flags(pformat, fmt); + fmt = extract_width(pformat, fmt); fmt = extract_precision(pformat, fmt); - extract_length_modifier(pformat, fmt); - free(start); + fmt = extract_length_modifier(pformat, fmt); + pformat->fmt_len = fmt - start + 1; + if (*fmt == '\0' || ft_strchr(SPECIFIERS_STR, *fmt) == NULL) + { + pformat->fmt_len--; + pformat->specifier = '_'; + } + else + pformat->specifier = *ft_strchr(SPECIFIERS_STR, *fmt); return (pformat); } |
