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