From 7ed66467ffe6dde9f4ca4975845d129772e4a851 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Mon, 29 May 2017 20:20:04 +0100 Subject: New utility function rdaddc_rep(). This is a function I should have introduced a lot earlier while writing the CHM output code, because I ended up with quite a lot of annoying loops to add zero-padding of various sizes by going round and round on the one-byte rdaddc(). --- misc.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'misc.c') diff --git a/misc.c b/misc.c index 8a426f2..04c2e14 100644 --- a/misc.c +++ b/misc.c @@ -2,6 +2,7 @@ * misc.c: miscellaneous useful items */ +#include #include #include "halibut.h" @@ -101,6 +102,19 @@ void rdaddsn(rdstringc *rs, char const *p, int len) { rs->pos += len; rs->text[rs->pos] = 0; } +void rdaddc_rep(rdstringc *rs, char c, int len) { + if (len <= 0) { + assert(len == 0); + return; + } + if (rs->pos >= rs->size - len) { + rs->size = rs->pos + len + 128; + rs->text = sresize(rs->text, rs->size, char); + } + memset(rs->text + rs->pos, c, len); + rs->pos += len; + rs->text[rs->pos] = 0; +} char *rdtrimc(rdstringc *rs) { rs->text = sresize(rs->text, rs->pos + 1, char); return rs->text; -- cgit v1.1