diff options
Diffstat (limited to 'include/bob.h')
-rw-r--r-- | include/bob.h | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/include/bob.h b/include/bob.h new file mode 100644 index 0000000..f2fb429 --- /dev/null +++ b/include/bob.h @@ -0,0 +1,48 @@ +#ifndef MLIB_BOB_H +#define MLIB_BOB_H + +#include <stddef.h> + +#include "__charN_t.h" +#include "__rune.h" + +#if !__MLIB_HAS_U8VIEW +# define __MLIB_HAS_U8VIEW 1 + +struct u8view { + const char8_t *p; + size_t len; +}; +#endif + +struct u8str { + char8_t *p; + size_t len, cap; +}; + +struct u8str *u8strinit(struct u8str *, size_t); +struct u8str *u8strgrow(struct u8str *, size_t); +struct u8str *u8strfit(struct u8str *); +void u8strfree(struct u8str); + +struct u8str *u8strpushr(struct u8str *, rune); +struct u8str *u8strpushstr(struct u8str *, const char *); +struct u8str *u8strpushu8(struct u8str *, struct u8view); + +[[gnu::always_inline]] +static inline struct u8view +u8strtou8(struct u8str s) +{ + return (struct u8view){.p = s.p, .len = s.len}; +} + +#define u8strpush(sb, x) \ + _Generic((x), \ + char: u8strpushr, \ + int: u8strpushr, \ + rune: u8strpushr, \ + char *: u8strpushstr, \ + struct u8view: u8strpushu8 \ + )((sb), (x)) + +#endif /* !MLIB_BOB_H */ |