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
76
stdme/src/printf/formatter/unsigned_decimal.c
Normal file
76
stdme/src/printf/formatter/unsigned_decimal.c
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* unsigned_decimal.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maix <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/18 01:44:35 by maix #+# #+# */
|
||||
/* Updated: 2023/12/11 19:19:59 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/mem/mem_alloc_array.h"
|
||||
#include "me/mem/mem_set.h"
|
||||
#include "me/printf/formatter/utils.h"
|
||||
#include "me/printf/printf.h"
|
||||
#include "me/string/str_clone.h"
|
||||
#include "me/string/str_len.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#define UINT_INLINE_BUF 21
|
||||
|
||||
static void itoa_inner(t_u64 nb, t_str out)
|
||||
{
|
||||
t_u64 modulus;
|
||||
bool need_print;
|
||||
char c;
|
||||
t_usize idx;
|
||||
|
||||
need_print = false;
|
||||
modulus = 10000000000000000000u;
|
||||
idx = 0;
|
||||
while (modulus)
|
||||
{
|
||||
c = (char)(nb / modulus) + '0';
|
||||
if (c != '0' || need_print)
|
||||
{
|
||||
out[idx++] = c;
|
||||
need_print = true;
|
||||
}
|
||||
nb = nb % modulus;
|
||||
modulus /= 10;
|
||||
}
|
||||
}
|
||||
|
||||
static t_str itoa_u64(t_u64 nb)
|
||||
{
|
||||
char out[UINT_INLINE_BUF];
|
||||
t_u64 n;
|
||||
|
||||
n = (t_u64)nb;
|
||||
mem_set(out, 0, UINT_INLINE_BUF);
|
||||
if (nb == 0)
|
||||
out[0] = '0';
|
||||
else
|
||||
itoa_inner(n, out);
|
||||
return (str_clone(out));
|
||||
}
|
||||
|
||||
void printf_u(t_printf_arg data, t_printf_func f)
|
||||
{
|
||||
t_u64 value;
|
||||
t_str start_num;
|
||||
t_str void_write;
|
||||
|
||||
value = *(t_u64 *)data.argument;
|
||||
start_num = itoa_u64(value);
|
||||
handle_weird_precision_stuff(&data, (t_prec_strs){.out = &start_num,
|
||||
.free_out = true, .pretty = &void_write}, value);
|
||||
pad_and_stuff(
|
||||
(t_pad_and_stuff_args){\
|
||||
.fill_zero = 0, .fill = 0, .len = str_len(start_num), \
|
||||
.pretty = NULL, .pretty_len = 0, .str = start_num, \
|
||||
.allow_zero_fill = true, .sign = NULL, .sign_len = 0, }, data, f);
|
||||
free(start_num);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue