Started from buttom go to the sky
This commit is contained in:
parent
96215449bd
commit
f811e55dea
4781 changed files with 10121 additions and 1743 deletions
70
stdme/src/printf/formatter/char.c
Normal file
70
stdme/src/printf/formatter/char.c
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* char.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/18 18:12:11 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/11 19:18:48 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/mem/mem_set.h"
|
||||
#include "me/printf/formatter/utils.h"
|
||||
#include "me/printf/printf.h"
|
||||
#include "me/string/str_len.h"
|
||||
#include "me/string/str_substring.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
void printf_c(t_printf_arg data, t_printf_func f)
|
||||
{
|
||||
char value[2];
|
||||
t_str start_num;
|
||||
|
||||
value[0] = *(char *)data.argument;
|
||||
value[1] = 0;
|
||||
start_num = &value[0];
|
||||
pad_and_stuff(
|
||||
(t_pad_and_stuff_args){\
|
||||
.fill_zero = 0, .fill = 0, .len = 1, .pretty = "", .pretty_len = 0, \
|
||||
.str = start_num, .allow_zero_fill = false, .sign = NULL, \
|
||||
.sign_len = 0, }, data, f);
|
||||
}
|
||||
|
||||
t_usize printf_s_inner(t_str *value, t_printf_arg *data, t_printf_func *f)
|
||||
{
|
||||
t_usize len;
|
||||
|
||||
if (*value == NULL)
|
||||
{
|
||||
if (data->flags & (PRECISION) && data->extra.precision < 6)
|
||||
*value = "";
|
||||
else
|
||||
*value = "(null)";
|
||||
}
|
||||
len = str_len(*value);
|
||||
if (data->flags & (PRECISION) && len > data->extra.precision)
|
||||
len = data->extra.precision;
|
||||
if (data->flags & (PRECISION) && len < data->extra.precision)
|
||||
data->extra.precision = len;
|
||||
(void)(f);
|
||||
return (len);
|
||||
}
|
||||
|
||||
void printf_s(t_printf_arg data, t_printf_func f)
|
||||
{
|
||||
t_str value;
|
||||
t_str start_num;
|
||||
t_usize len;
|
||||
|
||||
value = (t_str)data.argument;
|
||||
len = printf_s_inner(&value, &data, &f);
|
||||
start_num = str_substring(value, 0, len);
|
||||
pad_and_stuff(
|
||||
(t_pad_and_stuff_args){\
|
||||
.fill_zero = 0, .fill = 0, .len = len, .pretty = "", .pretty_len = 0, \
|
||||
.str = start_num, .allow_zero_fill = false, .sign = NULL, \
|
||||
.sign_len = 0, }, data, f);
|
||||
free(start_num);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue