Added <num>_to_str functions
This commit is contained in:
parent
aafd056f49
commit
698d1088e2
21 changed files with 963 additions and 60 deletions
|
|
@ -10,11 +10,8 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/types.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/vec/vec_buf_str.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
|
|
@ -45,7 +42,7 @@ t_error vec_buf_str_push(t_vec_buf_str *vec, t_string element)
|
|||
/// Return true in case of an error
|
||||
t_error vec_buf_str_reserve(t_vec_buf_str *vec, t_usize wanted_capacity)
|
||||
{
|
||||
size_t new_capacity;
|
||||
size_t new_capacity;
|
||||
|
||||
if (vec == NULL)
|
||||
return (ERROR);
|
||||
|
|
@ -54,7 +51,8 @@ t_error vec_buf_str_reserve(t_vec_buf_str *vec, t_usize wanted_capacity)
|
|||
new_capacity = (vec->capacity * 3) / 2 + 1;
|
||||
while (wanted_capacity > new_capacity)
|
||||
new_capacity = (new_capacity * 3) / 2 + 1;
|
||||
vec->buffer = mem_realloc_array(vec->buffer, new_capacity, sizeof(t_string));
|
||||
vec->buffer =
|
||||
mem_realloc_array(vec->buffer, new_capacity, sizeof(t_string));
|
||||
vec->capacity = new_capacity;
|
||||
}
|
||||
return (NO_ERROR);
|
||||
|
|
@ -83,6 +81,8 @@ t_error vec_buf_str_pop(t_vec_buf_str *vec, t_string *value)
|
|||
/// This function is safe to call with `free_elem` being NULL
|
||||
void vec_buf_str_free(t_vec_buf_str vec)
|
||||
{
|
||||
if (vec.buffer == NULL)
|
||||
return;
|
||||
if (vec.free_func)
|
||||
{
|
||||
while (vec.len)
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ t_error vec_buf_str_find(t_vec_buf_str *vec,
|
|||
idx = 0;
|
||||
while (idx < vec->len)
|
||||
{
|
||||
if (fn(&vec->buffer[idx]))
|
||||
if (fn((const t_string *)&vec->buffer[idx]))
|
||||
{
|
||||
*index = idx;
|
||||
return (NO_ERROR);
|
||||
|
|
@ -48,7 +48,7 @@ t_error vec_buf_str_find_starting(t_vec_buf_str *vec,
|
|||
idx = starting_index;
|
||||
while (idx < vec->len)
|
||||
{
|
||||
if (fn(&vec->buffer[idx]))
|
||||
if (fn((const t_string *)&vec->buffer[idx]))
|
||||
{
|
||||
*index = idx;
|
||||
return (NO_ERROR);
|
||||
|
|
@ -69,7 +69,7 @@ t_error vec_buf_str_all(t_vec_buf_str *vec,
|
|||
*result = true;
|
||||
while (*result && idx < vec->len)
|
||||
{
|
||||
if (!fn(&vec->buffer[idx]))
|
||||
if (!fn((const t_string *)&vec->buffer[idx]))
|
||||
*result = false;
|
||||
idx++;
|
||||
}
|
||||
|
|
@ -87,7 +87,7 @@ t_error vec_buf_str_any(t_vec_buf_str *vec,
|
|||
*result = false;
|
||||
while (*result && idx < vec->len)
|
||||
{
|
||||
if (fn(&vec->buffer[idx]))
|
||||
if (fn((const t_string *)&vec->buffer[idx]))
|
||||
*result = true;
|
||||
idx++;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,11 +10,8 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/types.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/vec/vec_str.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
|
|
@ -45,7 +42,7 @@ t_error vec_str_push(t_vec_str *vec, t_str element)
|
|||
/// Return true in case of an error
|
||||
t_error vec_str_reserve(t_vec_str *vec, t_usize wanted_capacity)
|
||||
{
|
||||
size_t new_capacity;
|
||||
size_t new_capacity;
|
||||
|
||||
if (vec == NULL)
|
||||
return (ERROR);
|
||||
|
|
@ -54,7 +51,8 @@ t_error vec_str_reserve(t_vec_str *vec, t_usize wanted_capacity)
|
|||
new_capacity = (vec->capacity * 3) / 2 + 1;
|
||||
while (wanted_capacity > new_capacity)
|
||||
new_capacity = (new_capacity * 3) / 2 + 1;
|
||||
vec->buffer = mem_realloc_array(vec->buffer, new_capacity, sizeof(t_str));
|
||||
vec->buffer =
|
||||
mem_realloc_array(vec->buffer, new_capacity, sizeof(t_str));
|
||||
vec->capacity = new_capacity;
|
||||
}
|
||||
return (NO_ERROR);
|
||||
|
|
@ -83,6 +81,8 @@ t_error vec_str_pop(t_vec_str *vec, t_str *value)
|
|||
/// This function is safe to call with `free_elem` being NULL
|
||||
void vec_str_free(t_vec_str vec)
|
||||
{
|
||||
if (vec.buffer == NULL)
|
||||
return;
|
||||
if (vec.free_func)
|
||||
{
|
||||
while (vec.len)
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ t_error vec_str_find(t_vec_str *vec,
|
|||
idx = 0;
|
||||
while (idx < vec->len)
|
||||
{
|
||||
if (fn(&vec->buffer[idx]))
|
||||
if (fn((const t_str *)&vec->buffer[idx]))
|
||||
{
|
||||
*index = idx;
|
||||
return (NO_ERROR);
|
||||
|
|
@ -48,7 +48,7 @@ t_error vec_str_find_starting(t_vec_str *vec,
|
|||
idx = starting_index;
|
||||
while (idx < vec->len)
|
||||
{
|
||||
if (fn(&vec->buffer[idx]))
|
||||
if (fn((const t_str *)&vec->buffer[idx]))
|
||||
{
|
||||
*index = idx;
|
||||
return (NO_ERROR);
|
||||
|
|
@ -69,7 +69,7 @@ t_error vec_str_all(t_vec_str *vec,
|
|||
*result = true;
|
||||
while (*result && idx < vec->len)
|
||||
{
|
||||
if (!fn(&vec->buffer[idx]))
|
||||
if (!fn((const t_str *)&vec->buffer[idx]))
|
||||
*result = false;
|
||||
idx++;
|
||||
}
|
||||
|
|
@ -87,7 +87,7 @@ t_error vec_str_any(t_vec_str *vec,
|
|||
*result = false;
|
||||
while (*result && idx < vec->len)
|
||||
{
|
||||
if (fn(&vec->buffer[idx]))
|
||||
if (fn((const t_str *)&vec->buffer[idx]))
|
||||
*result = true;
|
||||
idx++;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,11 +10,8 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/types.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/vec/vec_u8.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
|
|
@ -45,7 +42,7 @@ t_error vec_u8_push(t_vec_u8 *vec, t_u8 element)
|
|||
/// Return true in case of an error
|
||||
t_error vec_u8_reserve(t_vec_u8 *vec, t_usize wanted_capacity)
|
||||
{
|
||||
size_t new_capacity;
|
||||
size_t new_capacity;
|
||||
|
||||
if (vec == NULL)
|
||||
return (ERROR);
|
||||
|
|
@ -54,7 +51,8 @@ t_error vec_u8_reserve(t_vec_u8 *vec, t_usize wanted_capacity)
|
|||
new_capacity = (vec->capacity * 3) / 2 + 1;
|
||||
while (wanted_capacity > new_capacity)
|
||||
new_capacity = (new_capacity * 3) / 2 + 1;
|
||||
vec->buffer = mem_realloc_array(vec->buffer, new_capacity, sizeof(t_u8));
|
||||
vec->buffer =
|
||||
mem_realloc_array(vec->buffer, new_capacity, sizeof(t_u8));
|
||||
vec->capacity = new_capacity;
|
||||
}
|
||||
return (NO_ERROR);
|
||||
|
|
@ -83,6 +81,8 @@ t_error vec_u8_pop(t_vec_u8 *vec, t_u8 *value)
|
|||
/// This function is safe to call with `free_elem` being NULL
|
||||
void vec_u8_free(t_vec_u8 vec)
|
||||
{
|
||||
if (vec.buffer == NULL)
|
||||
return;
|
||||
if (vec.free_func)
|
||||
{
|
||||
while (vec.len)
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ t_error vec_u8_find(t_vec_u8 *vec,
|
|||
idx = 0;
|
||||
while (idx < vec->len)
|
||||
{
|
||||
if (fn(&vec->buffer[idx]))
|
||||
if (fn((const t_u8 *)&vec->buffer[idx]))
|
||||
{
|
||||
*index = idx;
|
||||
return (NO_ERROR);
|
||||
|
|
@ -48,7 +48,7 @@ t_error vec_u8_find_starting(t_vec_u8 *vec,
|
|||
idx = starting_index;
|
||||
while (idx < vec->len)
|
||||
{
|
||||
if (fn(&vec->buffer[idx]))
|
||||
if (fn((const t_u8 *)&vec->buffer[idx]))
|
||||
{
|
||||
*index = idx;
|
||||
return (NO_ERROR);
|
||||
|
|
@ -69,7 +69,7 @@ t_error vec_u8_all(t_vec_u8 *vec,
|
|||
*result = true;
|
||||
while (*result && idx < vec->len)
|
||||
{
|
||||
if (!fn(&vec->buffer[idx]))
|
||||
if (!fn((const t_u8 *)&vec->buffer[idx]))
|
||||
*result = false;
|
||||
idx++;
|
||||
}
|
||||
|
|
@ -87,7 +87,7 @@ t_error vec_u8_any(t_vec_u8 *vec,
|
|||
*result = false;
|
||||
while (*result && idx < vec->len)
|
||||
{
|
||||
if (fn(&vec->buffer[idx]))
|
||||
if (fn((const t_u8 *)&vec->buffer[idx]))
|
||||
*result = true;
|
||||
idx++;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue