cwist
Modern C web framework with libttak runtime
Loading...
Searching...
No Matches
sstring.h
Go to the documentation of this file.
1
4#ifndef __CWIST_SSTRING_H__
5#define __CWIST_SSTRING_H__
6
7#include <string.h>
8#include <stdlib.h>
9#include <stdbool.h>
10#include <cwist/err/cwist_err.h>
11
12typedef struct cwist_sstring {
13 char *data;
14 bool is_fixed;
15 bool owns_storage;
16 bool borrows_buffer;
17 size_t size;
18 size_t capacity;
21 char *base;
23 size_t (*get_size)(struct cwist_sstring *str);
24 int (*compare)(
25 struct cwist_sstring *left,
26 const struct cwist_sstring *right);
27 cwist_error_t (*copy)(struct cwist_sstring *str, const struct cwist_sstring *from);
28 cwist_error_t (*append)(struct cwist_sstring *str, const struct cwist_sstring *from);
41
44
51cwist_error_t cwist_sstring_append_len(cwist_sstring *str, const char *data, size_t len);
52
56cwist_error_t cwist_sstring_assign_len(cwist_sstring *str, const char *data, size_t len);
57
61cwist_error_t cwist_sstring_borrow(cwist_sstring *str, const char *data, size_t len);
62
66cwist_error_t cwist_sstring_adopt_len(cwist_sstring *str, char *buf, size_t len);
67
77cwist_error_t cwist_sstring_adopt_region(cwist_sstring *str, char *base, size_t offset, size_t len);
78
83
88
93
98
102cwist_error_t cwist_sstring_change_size(cwist_sstring *str, size_t size, bool blow_data);
103
108
113
118
122cwist_error_t cwist_sstring_seek(cwist_sstring *str, char *substr, int location);
123
127cwist_error_t cwist_sstring_copy(cwist_sstring *origin, char *destination);
128
133
137int cwist_sstring_compare(cwist_sstring *str, const char *compare_to);
138
143
148
152cwist_sstring *cwist_sstring_substr(cwist_sstring *str, int start, int length);
153
165
166#endif
cwist_sstring_error_t
Definition sstring.h:185
@ ERR_SSTRING_NULL_STRING
Definition sstring.h:188
@ ERR_SSTRING_CONSTANT
Definition sstring.h:189
@ ERR_SSTRING_OUTOFBOUND
Definition sstring.h:192
@ ERR_SSTRING_RESIZE_TOO_LARGE
Definition sstring.h:191
@ ERR_SSTRING_ZERO_LENGTH
Definition sstring.h:187
@ ERR_SSTRING_RESIZE_TOO_SMALL
Definition sstring.h:190
@ ERR_SSTRING_OKAY
Definition sstring.h:186
int cwist_sstring_compare(cwist_sstring *str, const char *compare_to)
Compare with a C string.
Definition sstring.c:852
cwist_error_t cwist_sstring_append_len(cwist_sstring *str, const char *data, size_t len)
Append raw bytes with length.
Definition sstring.c:212
cwist_error_t cwist_sstring_adopt_region(cwist_sstring *str, char *base, size_t offset, size_t len)
Adopt a heap buffer as a region view without copying.
Definition sstring.c:183
size_t cwist_sstring_get_size(cwist_sstring *str)
Get the current size.
Definition sstring.c:306
cwist_sstring * cwist_sstring_create(void)
Create a new sstring instance.
Definition sstring.c:802
cwist_error_t cwist_sstring_init(cwist_sstring *str)
Initialize an sstring.
Definition sstring.c:250
cwist_sstring * cwist_sstring_substr(cwist_sstring *str, int start, int length)
Extract a substring.
Definition sstring.c:863
cwist_error_t cwist_sstring_append(cwist_sstring *str, const char *data)
Append a C string.
Definition sstring.c:559
cwist_error_t cwist_sstring_assign_len(cwist_sstring *str, const char *data, size_t len)
Assign raw bytes with length.
Definition sstring.c:88
cwist_error_t cwist_sstring_assign(cwist_sstring *str, const char *data)
Assign a C string.
Definition sstring.c:504
cwist_error_t cwist_sstring_copy(cwist_sstring *origin, char *destination)
Copy to a C string buffer.
Definition sstring.c:766
cwist_error_t cwist_sstring_append_sstring(cwist_sstring *str, const cwist_sstring *from)
Append another sstring.
Definition sstring.c:700
struct cwist_sstring cwist_sstring
void cwist_sstring_destroy(cwist_sstring *str)
Destroy an sstring instance.
Definition sstring.c:823
cwist_error_t cwist_sstring_change_size(cwist_sstring *str, size_t size, bool blow_data)
Change the internal buffer size.
Definition sstring.c:417
cwist_error_t cwist_sstring_borrow(cwist_sstring *str, const char *data, size_t len)
Borrow an external buffer without copying.
Definition sstring.c:122
cwist_error_t cwist_sstring_rtrim(cwist_sstring *str)
Right-trim whitespace.
Definition sstring.c:365
cwist_error_t cwist_sstring_trim(cwist_sstring *str)
Trim whitespace from both ends.
Definition sstring.c:404
cwist_error_t cwist_sstring_ltrim(cwist_sstring *str)
Left-trim whitespace.
Definition sstring.c:329
cwist_error_t cwist_sstring_copy_sstring(cwist_sstring *origin, const cwist_sstring *from)
Copy from another sstring.
Definition sstring.c:786
cwist_error_t cwist_sstring_seek(cwist_sstring *str, char *substr, int location)
Seek a substring at a location.
Definition sstring.c:741
int cwist_sstring_compare_sstring(cwist_sstring *left, const cwist_sstring *right)
Compare two sstrings.
Definition sstring.c:320
cwist_error_t cwist_sstring_adopt_len(cwist_sstring *str, char *buf, size_t len)
Adopt a heap buffer, taking ownership without copying.
Definition sstring.c:151
cwist_err.h interface.
Integrated error structure used throughout the system.
Definition cwist_err.h:72
int(* compare)(struct cwist_sstring *left, const struct cwist_sstring *right)
Should mimic strcmp, internally use strncmp.
Definition sstring.h:27
size_t size
Definition sstring.h:20
char * base
Definition sstring.h:24
char * data
Access directly only when raw handling is necessary.
Definition sstring.h:15
size_t capacity
Definition sstring.h:21
cwist_error_t(* append)(struct cwist_sstring *str, const struct cwist_sstring *from)
Append another sstring.
Definition sstring.h:35
cwist_error_t(* copy)(struct cwist_sstring *str, const struct cwist_sstring *from)
Definition sstring.h:30
bool owns_storage
Definition sstring.h:17
size_t(* get_size)(struct cwist_sstring *str)
Definition sstring.h:26
bool is_fixed
Definition sstring.h:16
bool borrows_buffer
data is borrowed (static/arena); never freed, detached on mutation
Definition sstring.h:18