2016-11-06 02:42:17 -08:00
|
|
|
#ifndef _SB_H__
|
|
|
|
#define _SB_H__
|
|
|
|
|
|
|
|
#include <stddef.h>
|
|
|
|
|
|
|
|
struct ty_sb {
|
|
|
|
char *buf;
|
2016-11-06 10:44:35 -08:00
|
|
|
size_t gap;
|
2016-11-06 02:42:17 -08:00
|
|
|
size_t len;
|
|
|
|
size_t alloc;
|
|
|
|
};
|
|
|
|
|
2016-11-06 10:44:35 -08:00
|
|
|
int ty_sb_add(struct ty_sb *sb, const char *s, size_t len);
|
2020-05-25 13:38:39 -07:00
|
|
|
#define TY_SB_ADD(_SB, _S) ty_sb_add(_SB, _S, strlen(_S))
|
2016-11-06 10:44:35 -08:00
|
|
|
void ty_sb_spaces_rtrim(struct ty_sb *sb);
|
2020-05-15 14:15:18 -07:00
|
|
|
void ty_sb_spaces_ltrim(struct ty_sb *sb);
|
2020-05-23 15:05:29 -07:00
|
|
|
int ty_sb_prepend(struct ty_sb *sb, const char *s, size_t len);
|
2020-05-25 13:38:39 -07:00
|
|
|
#define TY_SB_PREPEND(_SB, _S) ty_sb_prepend(_SB, _S, strlen(_S))
|
2016-11-06 10:44:35 -08:00
|
|
|
char *ty_sb_steal_buf(struct ty_sb *sb);
|
2020-05-23 15:05:29 -07:00
|
|
|
void ty_sb_lskip(struct ty_sb *sb, size_t len);
|
|
|
|
void ty_sb_rskip(struct ty_sb *sb, size_t len);
|
2016-11-06 10:44:35 -08:00
|
|
|
void ty_sb_free(struct ty_sb *sb);
|
2016-11-06 02:42:17 -08:00
|
|
|
|
2020-05-24 10:37:58 -07:00
|
|
|
#define sbstartswith(SB, ConstRef) \
|
|
|
|
(((SB)->len >= sizeof(ConstRef) -1) \
|
|
|
|
&& (!strncmp((SB)->buf, ConstRef, sizeof(ConstRef) - 1)))
|
2016-11-06 02:42:17 -08:00
|
|
|
#endif
|