2024-11-15 23:42:29 +00:00
|
|
|
#ifndef VSTR_INCLUDED
|
|
|
|
#define VSTR_INCLUDED
|
|
|
|
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
struct Vstr {
|
|
|
|
size_t len; // String len
|
2024-11-23 00:10:58 +00:00
|
|
|
char *buf; // String data
|
2024-11-15 23:42:29 +00:00
|
|
|
};
|
|
|
|
typedef struct Vstr Vstr;
|
|
|
|
|
|
|
|
#define Vstr_Fmt "%.*s"
|
|
|
|
#define Vstr_Arg(vstr) (int) (vstr).len, (vstr).buf
|
|
|
|
#define VSTR(cstr) vstr_n(cstr, sizeof(cstr) - 1)
|
|
|
|
#define VSTR_NULL vstr_n(NULL, 0)
|
|
|
|
|
2024-11-23 00:10:58 +00:00
|
|
|
size_t pack_vstr(unsigned char *buffer, Vstr *vstr);
|
|
|
|
void unpack_vstr(unsigned char *buffer, Vstr *vstr);
|
|
|
|
size_t pack_vstr_array(unsigned char *buffer, Vstr *array, size_t count);
|
|
|
|
Vstr *unpack_vstr_array(unsigned char *buffer, size_t *count);
|
2024-11-15 23:42:29 +00:00
|
|
|
Vstr vstr_s(const char *s);
|
|
|
|
Vstr vstr_n(const char *s, size_t n);
|
|
|
|
bool vstr_cmp(const Vstr v1, const Vstr v2);
|
|
|
|
const char *vstr_str(const Vstr haystack, const Vstr needle);
|
|
|
|
Vstr vstr_after_delim(const Vstr v, const char *delims);
|
|
|
|
Vstr vstr_before_delim(const Vstr v, const char *delims);
|
|
|
|
Vstr vstr_substr(Vstr v, size_t start, size_t stop);
|
|
|
|
Vstr vstr_trim(Vstr v);
|
|
|
|
Vstr vstr_trim_left(Vstr v);
|
|
|
|
Vstr vstr_trim_right(Vstr v);
|
2024-11-23 00:10:58 +00:00
|
|
|
|
|
|
|
|
2024-11-15 23:42:29 +00:00
|
|
|
#endif
|