added a few function to str_istream_t
This commit is contained in:
parent
8ddd9186b8
commit
ae4da6d73d
2 changed files with 29 additions and 0 deletions
|
|
@ -22,6 +22,17 @@ str_istream_t istrInitLen(const char *str, usize len) {
|
|||
return res;
|
||||
}
|
||||
|
||||
void istrScanf(str_istream_t *ctx, const char *fmt, ...) {
|
||||
va_list va;
|
||||
va_start(va, fmt);
|
||||
istrScanfV(ctx, fmt, va);
|
||||
va_end(va);
|
||||
}
|
||||
|
||||
void istrScanfV(str_istream_t *ctx, const char *fmt, va_list args) {
|
||||
vsscanf(ctx->cur, fmt, args);
|
||||
}
|
||||
|
||||
char istrGet(str_istream_t *ctx) {
|
||||
return *ctx->cur++;
|
||||
}
|
||||
|
|
@ -34,6 +45,11 @@ void istrIgnore(str_istream_t *ctx, char delim) {
|
|||
++i, ++ctx->cur);
|
||||
}
|
||||
|
||||
void istrIgnoreAndSkip(str_istream_t *ctx, char delim) {
|
||||
istrIgnore(ctx, delim);
|
||||
istrSkip(ctx, 1);
|
||||
}
|
||||
|
||||
char istrPeek(str_istream_t *ctx) {
|
||||
return *ctx->cur;
|
||||
}
|
||||
|
|
@ -75,6 +91,12 @@ void istrRewind(str_istream_t *ctx) {
|
|||
ctx->cur = ctx->start;
|
||||
}
|
||||
|
||||
void istrRewindN(str_istream_t *ctx, usize amount) {
|
||||
usize remaining = ctx->size - (ctx->cur - ctx->start);
|
||||
if (amount > remaining) amount = remaining;
|
||||
ctx->cur -= amount;
|
||||
}
|
||||
|
||||
usize istrTell(str_istream_t ctx) {
|
||||
return ctx.cur - ctx.start;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue