diff options
Diffstat (limited to 'src/blob.c')
-rw-r--r-- | src/blob.c | 19 |
1 files changed, 18 insertions, 1 deletions
@@ -47,7 +47,7 @@ int apk_blob_rsplit(apk_blob_t blob, char split, apk_blob_t *l, apk_blob_t *r) return 1; } -int apk_blob_splitstr(apk_blob_t blob, char *split, apk_blob_t *l, apk_blob_t *r) +int apk_blob_splitstr(apk_blob_t blob, const char *split, apk_blob_t *l, apk_blob_t *r) { int splitlen = strlen(split); char *pos = blob.ptr, *end = blob.ptr + blob.len - splitlen + 1; @@ -71,6 +71,23 @@ int apk_blob_splitstr(apk_blob_t blob, char *split, apk_blob_t *l, apk_blob_t *r } } +int apk_blob_for_each_segment(apk_blob_t blob, const char *split, + int (*cb)(void *ctx, apk_blob_t blob), void *ctx) +{ + apk_blob_t l, r; + int rc; + + r = blob; + while (apk_blob_splitstr(r, split, &l, &r)) { + rc = cb(ctx, l); + if (rc != 0) + return rc; + } + if (r.len > 0) + return cb(ctx, r); + return 0; +} + static int dx(int c) { if (c >= '0' && c <= '9') |