diff options
| author | realtradam <[email protected]> | 2023-03-08 00:19:55 -0500 |
|---|---|---|
| committer | realtradam <[email protected]> | 2023-03-08 00:19:55 -0500 |
| commit | 4b410af18ed7e76b42be1d2ab2ebdfe8e5bf97e8 (patch) | |
| tree | b6b20aa5470e240189c5e46288d9c261879d345c /src/rodeo_string.c | |
| parent | e58d0577634b1405a40a4b1ebd0a36323fa81970 (diff) | |
| download | RodeoKit-4b410af18ed7e76b42be1d2ab2ebdfe8e5bf97e8.tar.gz RodeoKit-4b410af18ed7e76b42be1d2ab2ebdfe8e5bf97e8.zip | |
Continued cleanup and refactoring. Added string type.
Diffstat (limited to 'src/rodeo_string.c')
| -rw-r--r-- | src/rodeo_string.c | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/src/rodeo_string.c b/src/rodeo_string.c new file mode 100644 index 0000000..72baae7 --- /dev/null +++ b/src/rodeo_string.c @@ -0,0 +1,91 @@ + +// internal +#include "rodeo.h" +#include "rodeo_types.h" + +// external +#define i_implement +#include <stc/cstr.h> + +typedef union cstr rodeo_string_t; + +rodeo_string_p +rodeo_string_create(const char *c_string) +{ + cstr* result = calloc(1, sizeof(cstr)); + if(c_string != NULL) + { + *result = cstr_from(c_string); + } + return (rodeo_string_p)result; +} + +void +rodeo_string_destroy(rodeo_string_p self) +{ + cstr_drop((cstr*)self); + //free(string); // the above already calls free on the entire pointer +} + +char* +rodeo_string_to_cstr(rodeo_string_p self) +{ + return cstr_data((cstr*)self); +} + +const char* +rodeo_string_to_constcstr(rodeo_string_p self) +{ + return cstr_str((cstr*)self); +} + +void +rodeo_string_insert( + rodeo_string_p self, + const rodeo_string_p insert, + intptr_t position +) +{ + cstr_insert_s((cstr*)self, position, *(cstr*)insert); +} + +void +rodeo_string_append( + rodeo_string_p self, + const rodeo_string_p append +) +{ + rodeo_string_insert( + self, + append, + cstr_size((cstr*)self) - 1 + ); +} + +void +rodeo_string_prepend( + rodeo_string_p self, + const rodeo_string_p prepend +) +{ + rodeo_string_insert( + self, + prepend, + 0 + ); +} + +void +rodeo_string_clear(rodeo_string_p self) +{ + cstr_clear((cstr*)self); +} + +void +rodeo_string_set(rodeo_string_p self, char* value) +{ + cstr_clear((cstr*)self); + cstr *temp = (cstr*)self; + *temp = cstr_from(value); +} + |
