diff options
| author | Charles <sircharlesaze@gmail.com> | 2020-01-17 10:56:16 +0100 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2020-01-17 10:56:16 +0100 |
| commit | fe37597119353ce183fc404417b81bd4702f64b7 (patch) | |
| tree | faa20a8352092c062e2fd272fff2104d9f2ddb3f /src/io/ft_printf/internals/convert_char.c | |
| parent | 2e5ca2ab6276b7b24895ade28e1533356ef523dc (diff) | |
| download | libft-fe37597119353ce183fc404417b81bd4702f64b7.tar.gz libft-fe37597119353ce183fc404417b81bd4702f64b7.tar.bz2 libft-fe37597119353ce183fc404417b81bd4702f64b7.zip | |
Splited include like src/, Adding feature toggle protection in header
Diffstat (limited to 'src/io/ft_printf/internals/convert_char.c')
| -rw-r--r-- | src/io/ft_printf/internals/convert_char.c | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/io/ft_printf/internals/convert_char.c b/src/io/ft_printf/internals/convert_char.c new file mode 100644 index 0000000..c5f3a93 --- /dev/null +++ b/src/io/ft_printf/internals/convert_char.c @@ -0,0 +1,53 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* convert_char.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/30 23:22:29 by cacharle #+# #+# */ +/* Updated: 2019/11/05 23:44:42 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_vasprintf.h" + +static char *handle_width_char(t_pformat *pformat, char *str) +{ + char *tmp; + int i; + + pformat->size = 1; + if (1 >= pformat->width) + return (str); + if ((tmp = (char*)malloc(sizeof(char) * (pformat->width + 1))) == NULL) + return (NULL); + if (pformat->flags & FLAG_MINUS) + { + ft_memcpy(tmp, str, (i = 1) + 1); + while (i < pformat->width) + tmp[i++] = ' '; + tmp[i] = 0; + } + else + { + i = 0; + while (i <= pformat->width - 1) + tmp[i++] = pformat->flags & FLAG_ZERO ? '0' : ' '; + ft_memcpy(tmp + i - 1, str, 2); + } + free(str); + pformat->size = pformat->width; + return (tmp); +} + +char *convert_char(va_list ap, t_pformat *pformat) +{ + char *str; + + if ((str = ft_strnew(2)) == NULL) + return (NULL); + str[0] = va_arg(ap, int); + str[1] = '\0'; + return (handle_width_char(pformat, str)); +} |
