You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
naka/include/str.h

46 lines
803 B

//! Better string handling
#ifndef _STR_H
#define _STR_H
#include <macros.h>
#include <ints.h>
#define STRF_OWNED AS(1ul << 5, int)
#define STRF_DERRIVED AS(1ul << 6, int)
enum str_ownership {
STR_NULL = 0,
STR_OWNED = STRF_OWNED,
STR_OWNED_STATIC,
STR_OWNED_MALLOC,
STR_OWNED_STACK,
STR_DERRIVED = STRF_DERRIVED,
STR_DERRIVED_STATIC,
STR_DERRIVED_MALLOC,
STR_DERRIVED_STACK,
};
//TODO: Complete rework
typedef struct string {
usize len, cap;
struct str_meta {
struct string* _shared derrived;
_Atomic usize refs;
void (*m_free)(void*);
enum str_ownership owned;
} meta;
union {
char* slice;
char str[];
};
} *str_t;
str_t* str_alloc(usize cap) _cconv(alloc);
char* str_new(const char* pIN cstr) _cconv(alloc);
void str_free(str_t* restrict str);
#endif /* _STR_H */