Re: [PATCH 01/14] strbuf: introduce strbuf_prefixf()
- From
Jonathan Nieder <jrnieder@gmail.com>
- Date
- Dec 3, 2014, 20:14 UTC
- Message-ID
- <20141203201416.GY6527@google.com>
- In-Reply-To
- <CAPig+cS6Z=UW80sn6ru15W29Vko-f2g4CUq0EQtWGU7ZjoJcog@mail.gmail.com>
Eric Sunshine wrote:
> On Wed, Dec 3, 2014 at 12:10 AM, Jonathan Nieder <jrnieder@gmail.com> wrote:
Show 17 quoted lines
>> +void strbuf_prefixf(struct strbuf *sb, const char *fmt, ...)
>> +{
>> + va_list ap;
>> + size_t pos, len;
>> +
>> + pos = sb->len;
>> +
>> + va_start(ap, fmt);
>> + strbuf_vaddf(sb, fmt, ap);
>> + va_end(ap);
>> +
>> + len = sb->len - pos;
>> + strbuf_insert(sb, 0, sb->buf + pos, len);
>> + strbuf_remove(sb, pos + len, len);
>
> Would a strbuf_setlen(sb, pos), rather than strbuf_remove(), make it
> clearer to the reader that this is merely performing a truncation?Good idea. I'll do that.
Thanks, Jonathan