1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
/*
20140203
20241208 - reformated using clang-format
Jan Mojzis
Public domain.
*/
#include "byte.h"
#include "e.h"
#include "bug.h"
#include "stringparser.h"
/*
The 'stringparser' function parses items from
comma-separated list. Empty strings are ignored.
*/
long long stringparser(const unsigned char *buf, long long len, long long pos,
const unsigned char **x, long long *xlen) {
long long i;
if (!buf || len < 0 || len > 1073741824 || pos < 0 || pos > 1073741824 ||
!x || !xlen)
bug_inval();
for (;;) {
if (pos >= len) return 0;
for (i = pos; i < len; ++i) {
if (buf[i] == ',') break;
}
*x = buf + pos;
*xlen = i - pos;
pos = i + 1;
if (*xlen != 0) return pos;
}
}
|