From a89f892640cf12f75c7ce18e6e88c70a8d3965ed Mon Sep 17 00:00:00 2001 From: Uneven Prankster Date: Sat, 23 Sep 2023 19:28:45 -0300 Subject: things can always be nicer :D --- src/text.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 src/text.c (limited to 'src/text.c') diff --git a/src/text.c b/src/text.c new file mode 100644 index 0000000..26c2eab --- /dev/null +++ b/src/text.c @@ -0,0 +1,64 @@ +#include "text.h" +#include "utils.h" + +#include +#include +#include + +size txt_length(const char *text) +{ + size length = 0; + + if(text != NULL){ + while (*text++) length++; + } + + return length; +} + +s8 create_s8(const size sz) +{ + return (s8){(u8*)RL_MALLOC(sz), sz}; +} + +void free_s8(s8* str) +{ + RL_FREE(str->buf); +} + +s8 cstr_to_s8(const char* str) +{ + size sz = txt_length(str) + 1; + s8 final = (s8){(u8*)RL_MALLOC(sz), sz - 1}; + memcpy(final.buf, str, sz); + return final; +} + +b32 equal_s8(const s8 one, const s8 other) +{ + // Get OUTTA here + if(one.len != other.len) + return false; + + for(i32 i = 0; i < one.len; ++i){ + if(one.buf[i] != other.buf[i]) + return false; + } + + return true; +} + +void add_s8(s8 dst, const s8 src, size* pos) +{ + memcpy(dst.buf + *pos, src.buf, src.len); + *pos += src.len; +} + +s8 load_file_text(const s8 path) +{ + char* shr = LoadFileText((const char*)path.buf); + s8 file = cstr_to_s8(shr); + UnloadFileText(shr); + + return file; +} \ No newline at end of file -- cgit v1.2.3