#ifndef CCAT_CAT_SDS_H
#define CCAT_CAT_SDS_H
#define SDS_MAX_PREALLOC (1024*1024)
#include <sys/types.h>
#include <stdarg.h>
#ifdef WIN32
#define inline __inline
#endif
#if defined(__cplusplus) || defined(c_plusplus)
extern "C" {
#endif
typedef char *sds;
typedef struct _sdshdr {
unsigned int len;
unsigned int free;
char buf[];
} sdshdr;
static inline size_t catsdslen(const sds s) {
sdshdr *sh = (sdshdr *) (s - (sizeof(sdshdr)));
return sh->len;
}
static inline size_t catsdsavail(const sds s) {
sdshdr *sh = (sdshdr *) (s - (sizeof(sdshdr)));
return sh->free;
}
sds catsdsnewlen(const void *init, size_t initlen);
sds catsdsnewEmpty(size_t preAlloclen);
sds catsdsnew(const char *init);
sds catsdsempty(void);
size_t catsdslen(const sds s);
sds catsdsdup(const sds s);
void catsdsfree(sds s);
size_t catsdsavail(const sds s);
sds catsdsgrowzero(sds s, size_t len);
sds catsdscatlen(sds s, const void *t, size_t len);
sds catsdscat(sds s, const char *t);
sds catsdscatchar(sds s, char c);
sds catsdscatsds(sds s, const sds t);
sds catsdscpylen(sds s, const char *t, size_t len);
sds catsdscpy(sds s, const char *t);
sds catsdscatvprintf(sds s, const char *fmt, va_list ap);
#ifdef __GNUC__
sds catsdscatprintf(sds s, const char *fmt, ...)
__attribute__((format(printf, 2, 3)));
#else
sds catsdscatprintf(sds s, const char *fmt, ...);
#endif
sds catsdscatfmt(sds s, char const *fmt, ...);
sds catsdstrim(sds s, const char *cset);
void catsdsrange(sds s, int start, int end);
void catsdsupdatelen(sds s);
void catsdsclear(sds s);
int catsdscmp(const sds s1, const sds s2);
sds *catsdssplitlen(const char *s, int len, const char *sep, int seplen, int *count);
void catsdsfreesplitres(sds *tokens, int count);
void catsdstolower(sds s);
void catsdstoupper(sds s);
sds catsdsfromlonglong(long long value);
sds catsdscatrepr(sds s, const char *p, size_t len);
sds *catsdssplitargs(const char *line, int *argc);
sds catsdsmapchars(sds s, const char *from, const char *to, size_t setlen);
sds catsdsjoin(char **argv, int argc, char *sep);
sds catsdsMakeRoomFor(sds s, size_t addlen);
void catsdsIncrLen(sds s, int incr);
sds catsdsRemoveFreeSpace(sds s);
size_t catsdsAllocSize(sds s);
#ifdef __cplusplus
}
#endif
#endif