From 82218f68108cdbd92f53f50a7ac1ee8c233a7c89 Mon Sep 17 00:00:00 2001 From: Marco Cetica Date: Mon, 22 Dec 2025 16:46:18 +0100 Subject: [PATCH] Started `String` type implementation --- src/string.h | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 src/string.h diff --git a/src/string.h b/src/string.h new file mode 100644 index 0000000..c4c7410 --- /dev/null +++ b/src/string.h @@ -0,0 +1,63 @@ +#ifndef STRING_H +#define STRING_H + +#define RESULT_MSG_SIZE 64 + +#include +#include +#include + +#include "vector.h" + +typedef vector_t *string_t; + +typedef enum { + STRING_OK = 0x0, + STRING_ERR_ALLOCATE, + STRING_ERR_OVERFLOW, + STRING_ERR_UNDERFLOW, + STRING_ERR_INVALID, + STRING_ERR_NOT_FOUND +} string_status_t; + +typedef struct { + string_status_t status; + uint8_t message[RESULT_MSG_SIZE]; + union { + string_t string; + vector_t *split_str; + bool string_eq; + char character; + } value; +} string_result_t; + +#ifdef __cplusplus +extern "C" { +#endif + +// Public APIs +string_result_t string_new(const char *c_str); +string_result_t string_eq(const string_t x, const string_t y, bool case_sensitive); +string_result_t string_concat(const string_t x, const string_t y); +string_result_t string_substr(const string_t dest, const string_t query); +string_result_t string_to_upper(string_t str); +string_result_t string_to_lower(string_t str); +string_result_t string_reverse(string_t str); +string_result_t string_split(const string_t str, const string_t delimiter); +string_result_t string_trim(string_t str); +string_result_t string_get_at(const string_t str, size_t idx); +string_result_t string_set_at(string_t str, size_t idx, char c); +string_result_t string_is_empty(const string_t str); +string_result_t string_last(const string_t str); +string_result_t string_destroy(string_t str); + +// Inline methods +static inline size_t string_length(const string_t str) { + return str ? vector_size(str) : 0; +} + +#ifdef __cplusplus +} +#endif + +#endif