#ifndef SV_INCLUDED #define SV_INCLUDED #include struct String_View { size_t len; const char *buf; }; typedef struct String_View SV; // Macros for String_View printf #define SV_FMT "%.*s" #define SV_ARG(sv) (int) (sv).len, (sv).buf // Null String #define SV_NULL sv_strn(NULL, 0) extern struct String_View sv_str(const char *s); extern struct String_View sv_strn(const char *s, size_t n); extern struct String_View sv_trim_left(struct String_View sv); extern struct String_View sv_trim_right(struct String_View sv); extern struct String_View sv_trim(struct String_View sv); extern int sv_eq(const struct String_View sv1, const struct String_View sv2); extern int sv_casecmp( const struct String_View sv1, const struct String_View sv2); extern struct String_View sv_before_delim(const struct String_View sv, const char *delims); extern struct String_View sv_after_delim(const struct String_View sv, const char *delims); extern struct String_View sv_str_str(const struct String_View haystack, const struct String_View needle); extern size_t sv_pack_size(const struct String_View sv); extern void sv_pack(unsigned char *buf, const struct String_View sv); extern struct String_View sv_unpack(unsigned char *buf); #endif