refactor: improve string methods

This commit is contained in:
2025-09-05 21:15:27 +02:00
parent 487afb5d6a
commit be154db6cf
10 changed files with 122 additions and 20 deletions

View File

@@ -51,7 +51,7 @@ int main(void) {
/* This hashmap will contain names as keys and a custom type as value */
size_t key_size = sizeof(char) * MAX_STR_LEN;
size_t value_size = sizeof(int) + sizeof(char) * MAX_STR_LEN;
mcl_hashmap_s *map = mcl_hm_init(my_hash_func, my_equal_fun, my_free_key, my_free_value, key_size, value_size);
mcl_hashmap_s *map = mcl_hm_new(my_hash_func, my_equal_fun, my_free_key, my_free_value, key_size, value_size);
/* Set a new value */
struct my_custom_type p1 = {

View File

@@ -5,7 +5,7 @@
int main(void) {
/* Allocate a new queue */
/* Always remember to check return values */
mcl_queue_s *queue = mcl_queue_init(3, sizeof(int));
mcl_queue_s *queue = mcl_queue_new(3, sizeof(int));
int val, out;

31
examples/string/str2.c Normal file
View File

@@ -0,0 +1,31 @@
#include <stdio.h>
#include "../../string/mystring.h"
int main(void) {
mcl_string_s *s1 = mcl_string_new("Hello, world!", 0);
mcl_string_s *s2 = mcl_string_new("Hello, world!", 0);
/* Dont' call mcl_string_cstr() more than once in the same printf function */
printf("s1: %s\n", mcl_string_cstr(s1));
printf("s2: %s\n", mcl_string_cstr(s2));
int ret = mcl_string_compare(s1, s2);
if (ret == 0) {
printf("Same string!\n");
}
mcl_string_clear(s1);
if (mcl_string_compare(s1, s2) != 0) {
printf("Not the same!\n");
}
mcl_string_toupper(s1);
mcl_string_tolower(s2);
printf("s1: %s\n", mcl_string_cstr(s1));
printf("s2: %s\n", mcl_string_cstr(s2));
mcl_string_free(s1);
mcl_string_free(s2);
}