Make str const and add str_slice

This commit is contained in:
2024-08-01 19:45:09 +02:00
parent 3dea8d4d95
commit c2ef63ae9c

View File

@@ -3,8 +3,16 @@
#include <stddef.h>
struct str {
char* data;
size_t len;
const char* data;
const size_t len;
};
#define str_attach(cstr) (struct str){.data = cstr, .len = sizeof(cstr)-1}
static inline struct str str_slice(struct str s, size_t begin, size_t end)
{
return (struct str) {
.data = s.data + begin,
.len = s.len - begin - end,
};
}