aboutsummaryrefslogtreecommitdiff
path: root/convert_ptr.c
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2019-11-06 00:02:56 +0100
committerCharles <sircharlesaze@gmail.com>2019-11-06 00:02:56 +0100
commitdafee6410a4ecd7400a83adf84ded3621f30a365 (patch)
tree401c4169f4c2bf849d33a6a0201ab47d0f0f7782 /convert_ptr.c
parente6d8f543af4c1a45f30495b90a3912b1c75f2be7 (diff)
downloadft_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 'convert_ptr.c')
-rw-r--r--convert_ptr.c28
1 files changed, 8 insertions, 20 deletions
diff --git a/convert_ptr.c b/convert_ptr.c
index 8c0797a..b07f3c6 100644
--- a/convert_ptr.c
+++ b/convert_ptr.c
@@ -6,12 +6,10 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/30 23:24:08 by cacharle #+# #+# */
-/* Updated: 2019/11/04 01:41:49 by cacharle ### ########.fr */
+/* Updated: 2019/11/05 23:43:45 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
-#include <stdarg.h>
-#include <stdlib.h>
#include "header.h"
char *convert_ptr(va_list ap, t_pformat *pformat)
@@ -20,22 +18,12 @@ char *convert_ptr(va_list ap, t_pformat *pformat)
str = ITOA_HEX_LOW((long long unsigned int)va_arg(ap, void*));
str = handle_precision(pformat, str);
- if (!(pformat->flags & FLAG_ZERO_PADDING))
- str = add_hex_prefix(str);
- if (pformat->flags & FLAG_ZERO_PADDING)
- pformat->min_width -= 2;
- str = handle_padding(pformat, str);
- if (pformat->flags & FLAG_ZERO_PADDING)
- str = add_hex_prefix(str);
+ if (!(pformat->flags & FLAG_ZERO))
+ str = ft_strjoin_free_snd("0x", str);
+ if (pformat->flags & FLAG_ZERO)
+ pformat->width -= 2;
+ str = handle_width(pformat, str);
+ if (pformat->flags & FLAG_ZERO)
+ str = ft_strjoin_free_snd("0x", str);
return (str);
}
-
-char *add_hex_prefix(char *str)
-{
- char *tmp;
-
- if ((tmp = ft_strjoin("0x", str)) == NULL)
- return (NULL);
- free(str);
- return (tmp);
-}