From 74336f37a3aab345147f24e6e2ccef259fbbb860 Mon Sep 17 00:00:00 2001 From: Maieul BOYER Date: Tue, 16 Jul 2024 19:42:30 +0200 Subject: [PATCH] Norminette 'static' functions --- stdme/include/me/convert/numbers_to_str.h | 138 ++++++++++++---------- stdme/src/convert/numbers_to_str.c | 21 ++-- 2 files changed, 86 insertions(+), 73 deletions(-) diff --git a/stdme/include/me/convert/numbers_to_str.h b/stdme/include/me/convert/numbers_to_str.h index 54b33fa8..8631936c 100644 --- a/stdme/include/me/convert/numbers_to_str.h +++ b/stdme/include/me/convert/numbers_to_str.h @@ -1,4 +1,3 @@ - /* ************************************************************************** */ /* */ /* ::: :::::::: */ @@ -7,58 +6,59 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/07/16 17:18:47 by maiboyer #+# #+# */ -/* Updated: 2024/07/16 17:19:31 by maiboyer ### ########.fr */ +/* Updated: 2024/07/16 19:41:42 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef NUMBERS_TO_STR_H -#define NUMBERS_TO_STR_H +# define NUMBERS_TO_STR_H -#include "me/types.h" +# include "me/types.h" -typedef struct s_num_str t_num_str; -typedef struct s_num_str_state t_num_str_state; +typedef struct s_num_str t_num_str; +typedef struct s_num_str_state t_num_str_state; -struct s_num_str +struct s_num_str { - t_u64 value; - bool is_nonnegative; - t_str base; - t_str prefix; + t_u64 value; + bool is_nonnegative; + t_str base; + t_str prefix; }; -struct s_num_str_state +struct s_num_str_state { - bool print; - bool zero; - char buffer[40]; - t_str base; - t_u64 base_len; - t_u64 modulus; - t_u64 value; - t_usize idx; + bool print; + bool zero; + char buffer[40]; + t_str base; + t_u64 base_len; + t_u64 modulus; + t_u64 value; + t_usize idx; }; -union u_nums { - t_u64 u64; - t_i64 i64; - t_u32 u32; - t_i32 i32; - t_u16 u16; - t_i16 i16; - t_u8 u8; - t_i8 i8; - +union u_nums +{ + t_u64 u64; + t_i64 i64; + t_u32 u32; + t_i32 i32; + t_u16 u16; + t_i16 i16; + t_u8 u8; + t_i8 i8; }; -/// @brief Convert a signed 8-bit integer to a string with a base and a prefix. +/// @brief Convert a signed 8-bit integer to a string with a base + a prefix. /// @param val The signed 8-bit integer to convert. /// @param base The base to use for the conversion. /// @param prefix The prefix to use for the conversion. /// @param out The output string. /// @return True in case of error, false otherwise. /// @note The base must be a string of at least 2 characters and no duplicates. -t_error i8_to_str_base_prefix(t_i8 val, t_str base, t_str prefix, t_str *out); +t_error i8_to_str_base_prefix(t_i8 val, t_str base, + t_str prefix, t_str *out); /// @brief Convert a signed 8-bit integer to a string with a base /// @param val The signed 8-bit integer to convert. @@ -66,22 +66,24 @@ t_error i8_to_str_base_prefix(t_i8 val, t_str base, t_str prefix, t_str *out); /// @param out The output string. /// @return True in case of error, false otherwise. /// @note The base must be a string of at least 2 characters and no duplicates. -t_error i8_to_str_base(t_i8 val, t_str base, t_str *out); +t_error i8_to_str_base(t_i8 val, t_str base, + t_str *out); /// @brief Convert a signed 8-bit integer to a string. /// @param val The signed 8-bit integer to convert. /// @param out The output string. /// @return True in case of error, false otherwise. -t_error i8_to_str(t_i8 val, t_str *out); +t_error i8_to_str(t_i8 val, t_str *out); -/// @brief Convert a unsigned 8-bit integer to a string with a base and a prefix. +/// @brief Convert a unsigned 8-bit integer to a string with a base + a prefix. /// @param val The unsigned 8-bit integer to convert. /// @param base The base to use for the conversion. /// @param prefix The prefix to use for the conversion. /// @param out The output string. /// @return True in case of error, false otherwise. /// @note The base must be a string of at least 2 characters and no duplicates. -t_error u8_to_str_base_prefix(t_u8 val, t_str base, t_str prefix, t_str *out); +t_error u8_to_str_base_prefix(t_u8 val, t_str base, + t_str prefix, t_str *out); /// @brief Convert a unsigned 8-bit integer to a string with a base /// @param val The unsigned 8-bit integer to convert. @@ -89,22 +91,24 @@ t_error u8_to_str_base_prefix(t_u8 val, t_str base, t_str prefix, t_str *out); /// @param out The output string. /// @return True in case of error, false otherwise. /// @note The base must be a string of at least 2 characters and no duplicates. -t_error u8_to_str_base(t_u8 val, t_str base, t_str *out); +t_error u8_to_str_base(t_u8 val, t_str base, + t_str *out); /// @brief Convert a unsigned 8-bit integer to a string. /// @param val The unsigned 8-bit integer to convert. /// @param out The output string. /// @return True in case of error, false otherwise. -t_error u8_to_str(t_u8 val, t_str *out); +t_error u8_to_str(t_u8 val, t_str *out); -/// @brief Convert a signed 16-bit integer to a string with a base and a prefix. +/// @brief Convert a signed 16-bit integer to a string with a base + a prefix. /// @param val The signed 16-bit integer to convert. /// @param base The base to use for the conversion. /// @param prefix The prefix to use for the conversion. /// @param out The output string. /// @return True in case of error, false otherwise. /// @note The base must be a string of at least 2 characters and no duplicates. -t_error i16_to_str_base_prefix(t_i16 val, t_str base, t_str prefix, t_str *out); +t_error i16_to_str_base_prefix(t_i16 val, t_str base, + t_str prefix, t_str *out); /// @brief Convert a signed 16-bit integer to a string with a base /// @param val The signed 16-bit integer to convert. @@ -112,22 +116,24 @@ t_error i16_to_str_base_prefix(t_i16 val, t_str base, t_str prefix, t_str *out); /// @param out The output string. /// @return True in case of error, false otherwise. /// @note The base must be a string of at least 2 characters and no duplicates. -t_error i16_to_str_base(t_i16 val, t_str base, t_str *out); +t_error i16_to_str_base(t_i16 val, t_str base, + t_str *out); /// @brief Convert a signed 16-bit integer to a string. /// @param val The signed 16-bit integer to convert. /// @param out The output string. /// @return True in case of error, false otherwise. -t_error i16_to_str(t_i16 val, t_str *out); +t_error i16_to_str(t_i16 val, t_str *out); -/// @brief Convert a unsigned 16-bit integer to a string with a base and a prefix. +/// @brief Convert a unsigned 16-bit integer to a string with a base + a prefix. /// @param val The unsigned 16-bit integer to convert. /// @param base The base to use for the conversion. /// @param prefix The prefix to use for the conversion. /// @param out The output string. /// @return True in case of error, false otherwise. /// @note The base must be a string of at least 2 characters and no duplicates. -t_error u16_to_str_base_prefix(t_u16 val, t_str base, t_str prefix, t_str *out); +t_error u16_to_str_base_prefix(t_u16 val, t_str base, + t_str prefix, t_str *out); /// @brief Convert a unsigned 16-bit integer to a string with a base /// @param val The unsigned 16-bit integer to convert. @@ -135,22 +141,24 @@ t_error u16_to_str_base_prefix(t_u16 val, t_str base, t_str prefix, t_str *out); /// @param out The output string. /// @return True in case of error, false otherwise. /// @note The base must be a string of at least 2 characters and no duplicates. -t_error u16_to_str_base(t_u16 val, t_str base, t_str *out); +t_error u16_to_str_base(t_u16 val, t_str base, + t_str *out); /// @brief Convert a unsigned 16-bit integer to a string. /// @param val The unsigned 16-bit integer to convert. /// @param out The output string. /// @return True in case of error, false otherwise. -t_error u16_to_str(t_u16 val, t_str *out); +t_error u16_to_str(t_u16 val, t_str *out); -/// @brief Convert a signed 32-bit integer to a string with a base and a prefix. +/// @brief Convert a signed 32-bit integer to a string with a base + a prefix. /// @param val The signed 32-bit integer to convert. /// @param base The base to use for the conversion. /// @param prefix The prefix to use for the conversion. /// @param out The output string. /// @return True in case of error, false otherwise. /// @note The base must be a string of at least 2 characters and no duplicates. -t_error i32_to_str_base_prefix(t_i32 val, t_str base, t_str prefix, t_str *out); +t_error i32_to_str_base_prefix(t_i32 val, t_str base, + t_str prefix, t_str *out); /// @brief Convert a signed 32-bit integer to a string with a base /// @param val The signed 32-bit integer to convert. @@ -158,22 +166,24 @@ t_error i32_to_str_base_prefix(t_i32 val, t_str base, t_str prefix, t_str *out); /// @param out The output string. /// @return True in case of error, false otherwise. /// @note The base must be a string of at least 2 characters and no duplicates. -t_error i32_to_str_base(t_i32 val, t_str base, t_str *out); +t_error i32_to_str_base(t_i32 val, t_str base, + t_str *out); /// @brief Convert a signed 32-bit integer to a string. /// @param val The signed 32-bit integer to convert. /// @param out The output string. /// @return True in case of error, false otherwise. -t_error i32_to_str(t_i32 val, t_str *out); +t_error i32_to_str(t_i32 val, t_str *out); -/// @brief Convert a unsigned 32-bit integer to a string with a base and a prefix. +/// @brief Convert a unsigned 32-bit integer to a string with a base + a prefix. /// @param val The unsigned 32-bit integer to convert. /// @param base The base to use for the conversion. /// @param prefix The prefix to use for the conversion. /// @param out The output string. /// @return True in case of error, false otherwise. /// @note The base must be a string of at least 2 characters and no duplicates. -t_error u32_to_str_base_prefix(t_u32 val, t_str base, t_str prefix, t_str *out); +t_error u32_to_str_base_prefix(t_u32 val, t_str base, + t_str prefix, t_str *out); /// @brief Convert a unsigned 32-bit integer to a string with a base /// @param val The unsigned 32-bit integer to convert. @@ -181,13 +191,14 @@ t_error u32_to_str_base_prefix(t_u32 val, t_str base, t_str prefix, t_str *out); /// @param out The output string. /// @return True in case of error, false otherwise. /// @note The base must be a string of at least 2 characters and no duplicates. -t_error u32_to_str_base(t_u32 val, t_str base, t_str *out); +t_error u32_to_str_base(t_u32 val, t_str base, + t_str *out); /// @brief Convert a unsigned 32-bit integer to a string. /// @param val The unsigned 32-bit integer to convert. /// @param out The output string. /// @return True in case of error, false otherwise. -t_error u32_to_str(t_u32 val, t_str *out); +t_error u32_to_str(t_u32 val, t_str *out); /// @brief Convert a signed 64-bit integer to a string with a base and a prefix. /// @param val The signed 64-bit integer to convert. @@ -196,7 +207,8 @@ t_error u32_to_str(t_u32 val, t_str *out); /// @param out The output string. /// @return True in case of error, false otherwise. /// @note The base must be a string of at least 2 characters and no duplicates. -t_error i64_to_str_base_prefix(t_i64 val, t_str base, t_str prefix, t_str *out); +t_error i64_to_str_base_prefix(t_i64 val, t_str base, + t_str prefix, t_str *out); /// @brief Convert a signed 64-bit integer to a string with a base /// @param val The signed 64-bit integer to convert. @@ -204,22 +216,24 @@ t_error i64_to_str_base_prefix(t_i64 val, t_str base, t_str prefix, t_str *out); /// @param out The output string. /// @return True in case of error, false otherwise. /// @note The base must be a string of at least 2 characters and no duplicates. -t_error i64_to_str_base(t_i64 val, t_str base, t_str *out); +t_error i64_to_str_base(t_i64 val, t_str base, + t_str *out); /// @brief Convert a signed 64-bit integer to a string. /// @param val The signed 64-bit integer to convert. /// @param out The output string. /// @return True in case of error, false otherwise. -t_error i64_to_str(t_i64 val, t_str *out); +t_error i64_to_str(t_i64 val, t_str *out); -/// @brief Convert a unsigned 64-bit integer to a string with a base and a prefix. +/// @brief Convert a unsigned 64-bit integer to a string with a base + a prefix. /// @param val The unsigned 64-bit integer to convert. /// @param base The base to use for the conversion. /// @param prefix The prefix to use for the conversion. /// @param out The output string. /// @return True in case of error, false otherwise. /// @note The base must be a string of at least 2 characters and no duplicates. -t_error u64_to_str_base_prefix(t_u64 val, t_str base, t_str prefix, t_str *out); +t_error u64_to_str_base_prefix(t_u64 val, t_str base, + t_str prefix, t_str *out); /// @brief Convert a unsigned 64-bit integer to a string with a base /// @param val The unsigned 64-bit integer to convert. @@ -227,13 +241,13 @@ t_error u64_to_str_base_prefix(t_u64 val, t_str base, t_str prefix, t_str *out); /// @param out The output string. /// @return True in case of error, false otherwise. /// @note The base must be a string of at least 2 characters and no duplicates. -t_error u64_to_str_base(t_u64 val, t_str base, t_str *out); +t_error u64_to_str_base(t_u64 val, t_str base, + t_str *out); /// @brief Convert a unsigned 64-bit integer to a string. /// @param val The unsigned 64-bit integer to convert. /// @param out The output string. /// @return True in case of error, false otherwise. -t_error u64_to_str(t_u64 val, t_str *out); - +t_error u64_to_str(t_u64 val, t_str *out); #endif /* NUMBERS_TO_STR_H */ diff --git a/stdme/src/convert/numbers_to_str.c b/stdme/src/convert/numbers_to_str.c index 3a35500c..b669fcce 100644 --- a/stdme/src/convert/numbers_to_str.c +++ b/stdme/src/convert/numbers_to_str.c @@ -6,7 +6,7 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/07/16 18:15:57 by maiboyer #+# #+# */ -/* Updated: 2024/07/16 18:19:42 by maiboyer ### ########.fr */ +/* Updated: 2024/07/16 19:39:57 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,10 +16,10 @@ #include "me/types.h" #include -static t_error _check_base(t_str base) +static t_error _check_base(t_str base) { - t_usize i; - t_usize j; + t_usize i; + t_usize j; i = 0; if (base == NULL) @@ -37,7 +37,7 @@ static t_error _check_base(t_str base) return (NO_ERROR); } -static void _set_modulus(t_num_str_state *s) +static void _set_modulus(t_num_str_state *s) { s->modulus = 0; s->base_len = str_len(s->base); @@ -45,7 +45,7 @@ static void _set_modulus(t_num_str_state *s) s->modulus += s->base_len; } -static char _get_char(t_u64 value, t_num_str_state *s) +static char _get_char(t_u64 value, t_num_str_state *s) { if (value == 0) s->zero = true; @@ -54,9 +54,9 @@ static char _get_char(t_u64 value, t_num_str_state *s) return (s->base[value]); } -static t_error _format_u64_base_innner(t_num_str_state *s) +static t_error _format_u64_base_innner(t_num_str_state *s) { - char c; + char c; if (s->value == 0) return (s->buffer[s->idx++] = _get_char(0, s), NO_ERROR); @@ -74,9 +74,9 @@ static t_error _format_u64_base_innner(t_num_str_state *s) return (NO_ERROR); } -t_error _format_u64(t_num_str args, t_str *out) +t_error _format_u64(t_num_str args, t_str *out) { - t_num_str_state s; + t_num_str_state s; t_str res; if (_check_base(args.base)) @@ -96,4 +96,3 @@ t_error _format_u64(t_num_str args, t_str *out) return (ERROR); return (*out = res, NO_ERROR); } -