diff options
Diffstat (limited to '')
| -rw-r--r-- | src/lisiblestd/string.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/lisiblestd/string.c b/src/lisiblestd/string.c new file mode 100644 index 0000000..3de3272 --- /dev/null +++ b/src/lisiblestd/string.c @@ -0,0 +1,33 @@ +#include "string.h" +#include "assert.h" +#include "src/lisiblestd/memory.h" + +#include <string.h> + +bool String_from_str(Allocator *allocator, String *string, const char *str) { + LSTD_ASSERT(allocator != NULL); + LSTD_ASSERT(string != NULL); + LSTD_ASSERT(str != NULL); + + usize length = strlen(str); + char *value = Allocator_allocate_array(allocator, length + 1, sizeof(char)); + if (!value) { + return false; + } + value[length] = '\0'; + + string->value = value; + string->length = length; + return true; +} + +void String_destroy(Allocator *allocator, String *string) { + LSTD_ASSERT(allocator != NULL); + LSTD_ASSERT(string != NULL); + Allocator_free(allocator, string->value); +} + +usize String_length(const String *string) { + LSTD_ASSERT(string != NULL); + return string->length; +} |
