strbuf.c: add strbuf_insertf() and strbuf_vinsertf()

Implement `strbuf_insertf()` and `strbuf_vinsertf()` to
insert data using a printf format string.

Original-idea-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Paul-Sebastian Ungureanu <ungureanupaulsebastian@gmail.com>
Helped-by: Johannes Sixt <j6t@kdbg.org>
Signed-off-by: Thomas Gummerer <t.gummerer@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Paul-Sebastian Ungureanu
2019-02-25 23:16:07 +00:00
committed by Junio C Hamano
parent e71c4a88f6
commit 5ef264dbdb
2 changed files with 45 additions and 0 deletions

View File

@ -244,6 +244,15 @@ void strbuf_addchars(struct strbuf *sb, int c, size_t n);
*/
void strbuf_insert(struct strbuf *sb, size_t pos, const void *, size_t);
/**
* Insert data to the given position of the buffer giving a printf format
* string. The contents will be shifted, not overwritten.
*/
void strbuf_vinsertf(struct strbuf *sb, size_t pos, const char *fmt,
va_list ap);
void strbuf_insertf(struct strbuf *sb, size_t pos, const char *fmt, ...);
/**
* Remove given amount of data from a given position of the buffer.
*/