#ifndef UTILS_STRING_H #define UTILS_STRING_H #include #include #include typedef struct { const char* data; size_t length; } StringView; typedef struct { char* data; size_t length; } HeapString; static inline HeapString heapstring_from(const char* text, size_t length) { char* allocated = malloc(sizeof(char) * length + 1); strncpy(allocated, text, length); HeapString string = { .data = allocated, .length = length, }; return string; } static inline HeapString heapstring_from_cstring(const char* text) { return heapstring_from(text, strlen(text)); } static inline void heapstring_destroy(HeapString* string) { free(string->data); } #endif