Started String type implementation

This commit is contained in:
2025-12-22 16:46:18 +01:00
parent f7838603a6
commit 8661488208

63
src/string.h Normal file
View File

@@ -0,0 +1,63 @@
#ifndef STRING_H
#define STRING_H
#define RESULT_MSG_SIZE 64
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#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