changed stuff
This commit is contained in:
parent
74336f37a3
commit
8d76630152
7 changed files with 31 additions and 192 deletions
|
|
@ -1,21 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* atoi.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/06 14:14:00 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/01/11 15:36:12 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef ATOI_H
|
||||
# define ATOI_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
t_i32 me_atoi(t_const_str str);
|
||||
t_i64 me_atoi_64(t_const_str str);
|
||||
|
||||
#endif
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* itoa.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/08/03 21:05:46 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:48:37 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef ITOA_H
|
||||
# define ITOA_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
t_str me_itoa(t_i32 nb);
|
||||
|
||||
#endif
|
||||
|
|
@ -25,8 +25,6 @@ char/isspace
|
|||
char/isupper
|
||||
char/tolower
|
||||
char/toupper
|
||||
convert/atoi
|
||||
convert/itoa
|
||||
convert/numbers_to_str
|
||||
fs/close
|
||||
fs/fs_internal
|
||||
|
|
|
|||
|
|
@ -1,61 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* atoi.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/06 14:14:00 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/01/11 15:37:28 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/char/char.h"
|
||||
#include "me/char/char.h"
|
||||
#include "me/convert/atoi.h"
|
||||
|
||||
t_i32 me_atoi(t_const_str str)
|
||||
{
|
||||
t_u64 out;
|
||||
t_u64 sign;
|
||||
t_usize i;
|
||||
|
||||
out = 0;
|
||||
i = 0;
|
||||
sign = 1;
|
||||
while (me_isspace(str[i]))
|
||||
i++;
|
||||
if (str[i] == '+' || str[i] == '-')
|
||||
if (str[i++] == '-')
|
||||
sign = -1;
|
||||
while (me_isdigit(str[i]))
|
||||
{
|
||||
out *= 10;
|
||||
out += str[i] - '0';
|
||||
i++;
|
||||
}
|
||||
return ((t_i32)(out * sign));
|
||||
}
|
||||
|
||||
t_i64 me_atoi_64(t_const_str str)
|
||||
{
|
||||
t_u64 out;
|
||||
t_u64 sign;
|
||||
t_usize i;
|
||||
|
||||
out = 0;
|
||||
i = 0;
|
||||
sign = 1;
|
||||
while (me_isspace(str[i]))
|
||||
i++;
|
||||
if (str[i] == '+' || str[i] == '-')
|
||||
if (str[i++] == '-')
|
||||
sign = -1;
|
||||
while (me_isdigit(str[i]))
|
||||
{
|
||||
out *= 10;
|
||||
out += str[i] - '0';
|
||||
i++;
|
||||
}
|
||||
return ((t_i64)(out * sign));
|
||||
}
|
||||
|
|
@ -1,69 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* itoa.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/08/03 21:05:46 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/11/10 14:56:42 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/convert/itoa.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/str/str.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
static void me_itoa_inner(t_u64 nb, t_str out)
|
||||
{
|
||||
t_i32 modulus;
|
||||
bool need_print;
|
||||
char c;
|
||||
t_usize idx;
|
||||
|
||||
need_print = false;
|
||||
modulus = 1000000000;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
t_str me_itoa(t_i32 nb)
|
||||
{
|
||||
char out[12];
|
||||
t_u64 n;
|
||||
|
||||
n = (t_u64)nb;
|
||||
mem_set(out, 0, 12);
|
||||
if (nb < 0)
|
||||
{
|
||||
out[0] = '-';
|
||||
me_itoa_inner(-n, out + 1);
|
||||
}
|
||||
else if (nb == 0)
|
||||
out[0] = '0';
|
||||
else
|
||||
me_itoa_inner(n, out);
|
||||
return (str_clone(out));
|
||||
}
|
||||
/*R
|
||||
int main(void)
|
||||
{
|
||||
me_putnbr(-2147483648);
|
||||
write(1, "\n", 1);
|
||||
me_putnbr(0);
|
||||
write(1, "\n", 1);
|
||||
me_putnbr(12345);
|
||||
return (0);
|
||||
}
|
||||
R*/
|
||||
|
|
@ -6,12 +6,12 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/16 17:57:04 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/07/07 17:40:18 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/07/17 15:38:55 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/convert/str_to_numbers.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/convert/atoi.h"
|
||||
#include "me/printf/formatter/utils.h"
|
||||
#include "me/printf/matchers/matchers.h"
|
||||
#include "me/str/str.h"
|
||||
|
|
@ -23,27 +23,28 @@
|
|||
bool handle_atoi_stuff(t_const_str fmt, t_usize *c_idx, t_usize *nxt,
|
||||
t_printf_arg *c_arg)
|
||||
{
|
||||
t_i32 atoi_res;
|
||||
|
||||
atoi_res = me_atoi(&fmt[*c_idx]);
|
||||
if (atoi_res < 0)
|
||||
t_str str;
|
||||
t_usize i;
|
||||
|
||||
i = 0;
|
||||
while (fmt[*c_idx + i] != '\0' && fmt[*c_idx + i] >= '0' && \
|
||||
fmt[*c_idx + i] <= '9')
|
||||
i++;
|
||||
str = str_substring(fmt, *c_idx, i);
|
||||
if (str == NULL)
|
||||
{
|
||||
*c_idx = *nxt;
|
||||
*nxt = (t_usize)(str_find_chr(fmt + *nxt + 1, '%') - fmt);
|
||||
return (false);
|
||||
}
|
||||
advance_atoi(fmt, c_idx);
|
||||
c_arg->extra.align = (t_u64)atoi_res;
|
||||
handle_prec_and_align(fmt, c_idx, c_arg);
|
||||
atoi_res = atoi(&fmt[*c_idx]);
|
||||
if (atoi_res < 0)
|
||||
if (str_to_u64(str, 10, &c_arg->extra.precision))
|
||||
{
|
||||
*c_idx = *nxt;
|
||||
*nxt = (t_usize)(str_find_chr(fmt + *nxt + 1, '%') - fmt);
|
||||
return (false);
|
||||
return (mem_free(str), false);
|
||||
}
|
||||
mem_free(str);
|
||||
advance_atoi(fmt, c_idx);
|
||||
c_arg->extra.precision = (t_u64)atoi_res;
|
||||
return (true);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue