diff options
| author | nodist <kevin.comas.git@gmail.com> | 2026-11-05 15:22:02 -0500 |
|---|---|---|
| committer | nodist <kevin.comas.git@gmail.com> | 2026-11-05 15:22:02 -0500 |
| commit | 7b9204a8680539bc4795a14f3d9a34e47981d0c3 (patch) | |
| tree | 7aa69bba0c9cbee0cafb638fd49af64958dbb228 /include/kpl/string.h | |
| parent | faa937cb09cd01f4ea94f5d7722a20e9c1246df0 (diff) | |
more objects and special slab for gc
Diffstat (limited to 'include/kpl/string.h')
| -rw-r--r-- | include/kpl/string.h | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/include/kpl/string.h b/include/kpl/string.h new file mode 100644 index 0000000..8c88825 --- /dev/null +++ b/include/kpl/string.h @@ -0,0 +1,29 @@ +/* + * KPL UTF-8 string and character methods + */ + +#pragma once + +/* + * Create new string + */ +kpl_object_string *kpl_object_string_create(kpl_thread *thread, int32_t bytes_size); + +/* + * Create a string from a c string + * Copies the c string + */ +inline kpl_object_string *kpl_object_string_from_c_string(kpl_thread *thread, const char *c_string) { + int32_t bytes_size = strlen(c_string); + kpl_object_string *object_string = kpl_object_string_create(thread, bytes_size); + object_string->bytes_length = bytes_size; + memcpy(object_string->bytes, c_string, bytes_size); + return object_string; +} + +/* + * Return string to gc before sweep + */ +inline void kpl_object_string_destroy(kpl_thread *thread, kpl_object_string *object_string) { + kpl_gc_delete(thread, (kpl_object*) object_string); +} |
