summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 0a0416a)
raw | patch | inline | side by side (parent: 0a0416a)
author | Jeff King <peff@peff.net> | |
Wed, 13 Jan 2010 17:36:42 +0000 (12:36 -0500) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Thu, 14 Jan 2010 17:25:15 +0000 (09:25 -0800) |
This is handy for creating strings which will be fed to printf() or
strbuf_expand().
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
strbuf_expand().
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/technical/api-strbuf.txt | patch | blob | history | |
strbuf.c | patch | blob | history | |
strbuf.h | patch | blob | history |
index 3b1da10f263dad08ad327d678da9ada32c83599f..afe27599511c5f6bab6e4f799fd18e7d83bdd454 100644 (file)
placeholder and replacement string. The array needs to be
terminated by an entry with placeholder set to NULL.
+`strbuf_addbuf_percentquote`::
+
+ Append the contents of one strbuf to another, quoting any
+ percent signs ("%") into double-percents ("%%") in the
+ destination. This is useful for literal data to be fed to either
+ strbuf_expand or to the *printf family of functions.
+
`strbuf_addf`::
Add a formatted string to the buffer.
diff --git a/strbuf.c b/strbuf.c
index 6cbc1fcfd86e45c85fda079f8bce8895adbcb3a4..af9130e52d877bc49748dd5e2db9c5912ab08837 100644 (file)
--- a/strbuf.c
+++ b/strbuf.c
return 0;
}
+void strbuf_addbuf_percentquote(struct strbuf *dst, const struct strbuf *src)
+{
+ int i, len = src->len;
+
+ for (i = 0; i < len; i++) {
+ if (src->buf[i] == '%')
+ strbuf_addch(dst, '%');
+ strbuf_addch(dst, src->buf[i]);
+ }
+}
+
size_t strbuf_fread(struct strbuf *sb, size_t size, FILE *f)
{
size_t res;
diff --git a/strbuf.h b/strbuf.h
index fa07ecf094bd3ef8997958fde29199f8fb6421b9..84ac9424b5446aa82ac79045ad020f9ecfc0f75f 100644 (file)
--- a/strbuf.h
+++ b/strbuf.h
const char *value;
};
extern size_t strbuf_expand_dict_cb(struct strbuf *sb, const char *placeholder, void *context);
+extern void strbuf_addbuf_percentquote(struct strbuf *dst, const struct strbuf *src);
__attribute__((format (printf,2,3)))
extern void strbuf_addf(struct strbuf *sb, const char *fmt, ...);