Make str const and add str_slice
This commit is contained in:
@@ -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,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user