36 #define kroundup32(x) (--(x), (x)|=(x)>>1, (x)|=(x)>>2, (x)|=(x)>>4, (x)|=(x)>>8, (x)|=(x)>>16, ++(x))
39 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
40 #define KS_ATTR_PRINTF(fmt, arg) __attribute__((__format__ (__printf__, fmt, arg)))
42 #define KS_ATTR_PRINTF(fmt, arg)
55 #define KSTRING_T kstring_t
74 int ksplit_core(
char *s,
int delimiter,
int *_max,
int **_offsets);
75 char *
kstrstr(
const char *str,
const char *pat,
int **_prep);
76 char *
kstrnstr(
const char *str,
const char *pat,
int n,
int **_prep);
77 void *
kmemmem(
const void *_str,
int n,
const void *_pat,
int m,
int **_prep);
89 static inline int ks_resize(
kstring_t *s,
size_t size)
95 if ((tmp = (
char*)realloc(s->
s, s->
m)))
108 static inline size_t ks_len(
kstring_t *s)
117 static inline char *ks_release(
kstring_t *s)
125 static inline int kputsn(
const char *p,
int l,
kstring_t *s)
127 if (s->
l + l + 1 >= s->
m) {
131 if ((tmp = (
char*)realloc(s->
s, s->
m)))
136 memcpy(s->
s + s->
l, p, l);
142 static inline int kputs(
const char *p,
kstring_t *s)
144 return kputsn(p, strlen(p), s);
147 static inline int kputc(
int c,
kstring_t *s)
149 if (s->
l + 1 >= s->
m) {
153 if ((tmp = (
char*)realloc(s->
s, s->
m)))
163 static inline int kputc_(
int c,
kstring_t *s)
165 if (s->
l + 1 > s->
m) {
169 if ((tmp = (
char*)realloc(s->
s, s->
m)))
178 static inline int kputsn_(
const void *p,
int l,
kstring_t *s)
180 if (s->
l + l > s->
m) {
184 if ((tmp = (
char*)realloc(s->
s, s->
m)))
189 memcpy(s->
s + s->
l, p, l);
194 static inline int kputw(
int c,
kstring_t *s)
200 do { buf[l++] = x%10 +
'0'; x /= 10; }
while (x > 0);
201 if (c < 0) buf[l++] =
'-';
202 if (s->
l + l + 1 >= s->
m) {
206 if ((tmp = (
char*)realloc(s->
s, s->
m)))
211 for (i = l - 1; i >= 0; --i) s->
s[s->
l++] = buf[i];
216 static inline int kputuw(
unsigned c,
kstring_t *s)
221 if (c == 0)
return kputc(
'0', s);
222 for (l = 0, x = c; x > 0; x /= 10) buf[l++] = x%10 +
'0';
223 if (s->
l + l + 1 >= s->
m) {
227 if ((tmp = (
char*)realloc(s->
s, s->
m)))
232 for (i = l - 1; i >= 0; --i) s->
s[s->
l++] = buf[i];
237 static inline int kputl(
long c,
kstring_t *s)
243 do { buf[l++] = x%10 +
'0'; x /= 10; }
while (x > 0);
244 if (c < 0) buf[l++] =
'-';
245 if (s->
l + l + 1 >= s->
m) {
249 if ((tmp = (
char*)realloc(s->
s, s->
m)))
254 for (i = l - 1; i >= 0; --i) s->
s[s->
l++] = buf[i];
263 static inline int *ksplit(
kstring_t *s,
int delimiter,
int *n)
265 int max = 0, *offsets = 0;