sv/include/sv.h

31 lines
692 B
C
Raw Permalink Normal View History

2025-07-10 23:51:28 +00:00
#ifndef SV_INCLUDED
#define SV_INCLUDED
#include <stddef.h>
2025-07-11 14:17:42 +00:00
#
2025-07-10 23:51:28 +00:00
// macros
#define SV(s) sv_str(s)
#define SV_NULL sv_strn(NULL, 0)
// printf macros
#define SV_FMT "%.*s"
#define SV_ARG(sv) (int) (sv).len, (sv).buf
struct String_View{
size_t len; // String lenght
const char *buf; // String data
};
typedef struct String_View SV;
SV sv_str(const char *s);
SV sv_strn(const char *s, size_t len);
2025-07-11 00:19:52 +00:00
SV sv_trim(SV s);
SV sv_trim_left(SV s);
SV sv_trim_right(SV s);
2025-07-11 14:17:42 +00:00
int sv_cmp(const SV s1, const SV s2);
2025-07-11 14:38:59 +00:00
int sv_casecmp(const SV s1, const SV s2);
2025-07-11 15:43:46 +00:00
SV before_delim(const SV s, char *delims);
2025-07-11 16:00:57 +00:00
SV after_delim(const SV s, char *delims);
SV sv_strstr(const SV haystack, const SV needle);
2025-07-10 23:51:28 +00:00
#endif