#include "jstring.h" #include #include #include JaggerString* JaggerString_create() { JaggerString* instance = (JaggerString*)malloc(sizeof(JaggerString)); instance->next = NULL; instance->len_str = NEW; instance->size_str = NEW; instance->index_str = NEW; instance->status_str = NEW; instance->sep_str = NEW; instance->letter = NULL; return instance; } void JaggerString_destroy(JaggerString* instance) { JaggerString* current = instance; while (current != NULL) { JaggerString* next = current->next; free(current); current = next; } } JaggerString* JaggerString_get_new_instance() { return JaggerString_create(); } void JaggerString_push(JaggerString* instance, const char* string) { char* str = (char*)malloc(strlen(string) + 1); JaggerString* current = instance; strcpy(str, string); size_t str_size = strlen(string); char* word = strtok(str, " "); while (word != NULL) { size_t word_size = strlen(word); for (size_t i = 0; i < word_size; ++i) { if (current->status_str == NEW) { current->status_str = WORD_START; current->sep_str = STR_START; current->len_str = str_size; current->size_str = 1; current->letter = word + i; current->index_str = 0; } else { current->status_str = (i == word_size - 1) ? WORD_END : WORD; current->sep_str = (i == 0) ? STR_START : STR; current->len_str = str_size; current->size_str = 1; current->letter = word + i; current->index_str = i; } if (i < word_size - 1) { current->next = JaggerString_create(); current = current->next; } } word = strtok(NULL, " "); if (word != NULL) { current->next = JaggerString_create(); current = current->next; } } free(str); } void JaggerString_remove(JaggerString* instance, const char* string) { // Implementiere die Logik zum Entfernen eines Strings } const char* JaggerString_get_index(JaggerString* instance, size_t index) { // Implementiere die Logik zum Abrufen eines Strings an einem bestimmten Index return NULL; } const char* JaggerString_get_exact(JaggerString* instance, size_t start, size_t end) { // Implementiere die Logik zum Abrufen eines exakten Substrings return NULL; } const char* JaggerString_get(JaggerString* instance) { static char result[1024]; // Annahme: Der resultierende String ist nicht länger als 1024 Zeichen result[0] = '\0'; JaggerString* current = instance; while (current != NULL) { if (current->sep_str == STR_START) { strcat(result, " "); } if (current->sep_str == WORD_START) { strcat(result, " "); } strncat(result, current->letter, 1); if (current->sep_str == WORD_END) { strcat(result, " "); } if (current->sep_str == STR_END) { strcat(result, " "); } current = current->next; } // Entferne führende und nachfolgende Leerzeichen if (result[0] == ' ') { memmove(result, result + 1, strlen(result)); } if (result[strlen(result) - 1] == ' ') { result[strlen(result) - 1] = '\0'; } return result; } void JaggerString_replace(JaggerString* instance, size_t index_1, size_t index_2) { // Implementiere die Logik zum Ersetzen von Strings } size_t JaggerString_get_len(JaggerString* instance) { return instance->len_str; } size_t JaggerString_get_size(JaggerString* instance, size_t index) { // Implementiere die Logik zum Abrufen der Größe eines Strings an einem bestimmten Index return 0; } size_t JaggerString_get_size_full(JaggerString* instance) { size_t total_size = 0; JaggerString* current = instance; while (current != NULL) { total_size += current->size_str; current = current->next; } return total_size; } size_t JaggerString_get_status(JaggerString* instance) { return instance->status_str; }