blob: 0d37a6f7cf526da786fec60ff8a8b2dc45085260 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
#include <string.h>
#include "strv.h"
strv_t strv(const char *s) {
return (strv_t) { s, strlen(s) };
}
int strv_split(strv_t *src, int chr, strv_t *dest) {
char *c = memchr(src->s, chr, src->n);
*dest = (strv_t) {
src->s,
c ? c - src->s : src->n
};
src->s = c ? c + 1 : &src->s[src->n];
src->n -= dest->n + !!c;
return dest->n > 0;
}
|