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> #include <stddef.h>
struct str { struct str {
char* data; const char* data;
size_t len; const size_t len;
}; };
#define str_attach(cstr) (struct str){.data = cstr, .len = sizeof(cstr)-1} #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,
};
}