mirror of
https://github.com/theoludwig/libcproject.git
synced 2024-12-11 21:13:00 +01:00
refactor: avoid usage of char*, instead use string_t
This commit is contained in:
parent
07e2f4db45
commit
c6df05e634
@ -37,7 +37,7 @@ void string_replace(string_t string, char search, char replace) {
|
||||
string[string_length] = '\0';
|
||||
}
|
||||
|
||||
void string_remove_character(char* string, char search) {
|
||||
void string_remove_character(string_t string, char search) {
|
||||
size_t string_length = string_get_length(string);
|
||||
for (size_t index = 0; index < string_length; index++) {
|
||||
if (string[index] == search) {
|
||||
|
@ -61,7 +61,7 @@ void string_replace(string_t string, char search, char replace);
|
||||
* @param search A character search value.
|
||||
* @since v4.1.0
|
||||
*/
|
||||
void string_remove_character(char* string, char search);
|
||||
void string_remove_character(string_t string, char search);
|
||||
|
||||
/**
|
||||
* @brief Removes all `character` from the start of a string.
|
||||
|
@ -24,7 +24,7 @@ string_t terminal_input() {
|
||||
void terminal_print_array(void* array, size_t array_size, size_t element_size, void (*print_element)(void*)) {
|
||||
printf("[");
|
||||
for (size_t index = 0; index < array_size; index++) {
|
||||
void* element = (char*)array + index * element_size;
|
||||
void* element = (string_t)array + index * element_size;
|
||||
print_element(element);
|
||||
bool is_last = index == array_size - 1;
|
||||
if (!is_last) {
|
||||
@ -47,11 +47,11 @@ void terminal_print_unsigned_long(void* value) {
|
||||
}
|
||||
|
||||
void terminal_print_char(void* value) {
|
||||
printf("%c", *(char*)value);
|
||||
printf("%c", *(string_t)value);
|
||||
}
|
||||
|
||||
void terminal_print_string(void* value) {
|
||||
printf("%s", (char*)value);
|
||||
printf("%s", (string_t)value);
|
||||
}
|
||||
|
||||
void terminal_print_stack(struct stack* stack, void (*print_element)(void*)) {
|
||||
@ -63,7 +63,7 @@ void terminal_print_stack(struct stack* stack, void (*print_element)(void*)) {
|
||||
struct stack_node* node_current = stack->first;
|
||||
while (node_current != NULL) {
|
||||
printf("|\t");
|
||||
void* element = (char*)node_current->data;
|
||||
void* element = node_current->data;
|
||||
print_element(&element);
|
||||
node_current = node_current->next;
|
||||
printf("\t|\n");
|
||||
@ -79,7 +79,7 @@ void terminal_print_queue(struct queue* queue, void (*print_element)(void*)) {
|
||||
struct queue_node* node_current = queue->first;
|
||||
while (node_current != NULL) {
|
||||
printf("|\t");
|
||||
void* element = (char*)node_current->data;
|
||||
void* element = node_current->data;
|
||||
print_element(&element);
|
||||
node_current = node_current->next;
|
||||
printf("\t|\n");
|
||||
@ -94,7 +94,7 @@ void terminal_print_linked_list(struct linked_list* linked_list, void (*print_el
|
||||
}
|
||||
struct linked_list_node* node_current = linked_list->head;
|
||||
while (node_current != NULL) {
|
||||
void* element = (char*)node_current->data;
|
||||
void* element = (string_t)node_current->data;
|
||||
node_current = node_current->next;
|
||||
print_element(&element);
|
||||
printf(" -> ");
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
#include "libcproject.h"
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
int main(int argc, string_t* argv) {
|
||||
if (argc != 2) {
|
||||
fprintf(stderr, "Usage: %s <version>\n", argv[0]);
|
||||
return EXIT_FAILURE;
|
||||
|
@ -10,7 +10,7 @@ void convert_test() {
|
||||
}
|
||||
|
||||
void convert_character_to_string_test() {
|
||||
char* result = convert_character_to_string('a');
|
||||
string_t result = convert_character_to_string('a');
|
||||
assert(assert_string_equal(result, "a"));
|
||||
free(result);
|
||||
|
||||
@ -77,7 +77,7 @@ void convert_string_to_number_test() {
|
||||
}
|
||||
|
||||
void convert_number_to_string_test() {
|
||||
char* result = convert_number_to_string(0);
|
||||
string_t result = convert_number_to_string(0);
|
||||
assert(assert_string_equal(result, "0"));
|
||||
free(result);
|
||||
|
||||
@ -143,7 +143,7 @@ void convert_number_to_string_test() {
|
||||
}
|
||||
|
||||
void convert_number_from_base_to_another_test() {
|
||||
char* result = convert_number_from_base_to_another("15", 10, 16);
|
||||
string_t result = convert_number_from_base_to_another("15", 10, 16);
|
||||
assert(assert_string_equal(result, "F"));
|
||||
free(result);
|
||||
|
||||
|
@ -203,7 +203,7 @@ void string_get_is_substring_test() {
|
||||
}
|
||||
|
||||
void string_get_formatted_number_test() {
|
||||
char* result = string_get_formatted_number(1000, " ");
|
||||
string_t result = string_get_formatted_number(1000, " ");
|
||||
assert(assert_string_equal(result, "1 000"));
|
||||
free(result);
|
||||
|
||||
@ -235,7 +235,7 @@ void string_get_formatted_number_test() {
|
||||
void string_get_last_occurence_of_character_test() {
|
||||
string_t string = "abcdef";
|
||||
|
||||
char* result = string_get_last_occurence_of_character(string, 'a');
|
||||
string_t result = string_get_last_occurence_of_character(string, 'a');
|
||||
assert(assert_string_equal(result, "abcdef"));
|
||||
free(result);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user