LibGame
v0.4.0
The LG Game Engine - Copyright (C) 2024 ETMSoftware
|
Functions | |
char * | str_n_cpy (char *dest, const char *src, size_t length) |
char * | str_n_cat (char *dest, const char *src, size_t length) |
char * | l_str_new (const char *str) |
char * | l_str_cat (char *dest, const char *src) |
char * | l_str_insert_at_b (char *dest, const char *src) |
void | l_str_free (char *str) |
void * | malloc2 (size_t size) |
void * | realloc2 (void *mem_block, size_t size) |
void * | calloc2 (size_t n_elements, size_t element_size) |
void | free2 (void *mem_block) |
const char * | readable_size (double size_bytes) |
const char * | itoa2 (long int n) |
char * | remove_char_from_str (char *str, char c) |
char * | remove_leading_whitespaces_from_str (char *str) |
char * | remove_trailing_whitespaces_from_str (char *str) |
char * | remove_surrounding_whitespaces_from_str (char *str) |
zboolean | str_is_num (const char *str2) |
zboolean | str_is_blank (const char *str) |
const char * | rnd_str (char mode, int length) |
=== A few strings and memory management functions ===
char* str_n_cpy | ( | char * | dest, |
const char * | src, | ||
size_t | length | ||
) |
Copy n bytes max from src to dest then add '\0' at end of dest.
char* str_n_cat | ( | char * | dest, |
const char * | src, | ||
size_t | length | ||
) |
Concanate n bytes max of src to dest then add '\0' at end of dest. Strings may not be identical and should not overlap.
char* l_str_new | ( | const char * | str | ) |
Create new_str (allocate memory) and copy str (can be NULL) to new_str.
char* l_str_cat | ( | char * | dest, |
const char * | src | ||
) |
Append src (can be NULL) to dest (re-allocate memory as necessary). dest must have been created by l_str_new()/malloc() - strings may overlap. Note: faster than l_str_insert_at_b().
char* l_str_insert_at_b | ( | char * | dest, |
const char * | src | ||
) |
Insert src (can be NULL) at the beginning of dest (re-allocate memory as necessary). dest must have been created by l_str_new()/malloc() - strings may overlap. Note: slower than l_str_cat().
void l_str_free | ( | char * | str | ) |
Free string created by l_str_new(), l_str_cat() or l_str_insert_at_b().
void* malloc2 | ( | size_t | size | ) |
Wrapper for malloc() which check returned value.
void* realloc2 | ( | void * | mem_block, |
size_t | size | ||
) |
Wrapper for realloc() which check returned value.
void* calloc2 | ( | size_t | n_elements, |
size_t | element_size | ||
) |
Wrapper for calloc() which check returned value.
void free2 | ( | void * | mem_block | ) |
Wrapper for free() which check returned value.
const char* readable_size | ( | double | size_bytes | ) |
Return size in readable format (KiB, MiB, GiB, TiB, ...) *** Allow up to N_SIMULTANEOUS_CALLS simultaneous calls *** Convention: we assume 2.5 MiB = 2 MiB + [0.5 x 1024 = 512] KiB, not 500 KiB. Otherwise, there is no way to express a value in the range 1000 - 1023, so x.y MiB = x MiB + 0.y MiB, that is: not y x 100 KiB but y x 102.4 KiB.
const char* itoa2 | ( | long int | n | ) |
itoa() is not ANSI C so this one could be useful. *** Allow up to N_SIMULTANEOUS_CALLS simultaneous calls ***
char* remove_char_from_str | ( | char * | str, |
char | c | ||
) |
Modify string in place.
char* remove_leading_whitespaces_from_str | ( | char * | str | ) |
Modify string in place.
char* remove_trailing_whitespaces_from_str | ( | char * | str | ) |
Modify string in place.
char* remove_surrounding_whitespaces_from_str | ( | char * | str | ) |
Modify string in place.
zboolean str_is_num | ( | const char * | str2 | ) |
Check that str contains only digits (at least one) and whitespaces (may start and/or end with whitespaces), meaning numerical value is integer >= 0.
zboolean str_is_blank | ( | const char * | str | ) |
Check that str contains only whitespaces or is empty.
const char* rnd_str | ( | char | mode, |
int | length | ||
) |
Generate a random string up to 1023 chars long. mode = a -> alpha / d -> digits / b -> both