diff options
author | Nicolas Zingilé <nicolas.zingile@open.eurogiciel.org> | 2014-11-17 17:01:18 +0100 |
---|---|---|
committer | Nicolas Zingilé <nicolas.zingile@open.eurogiciel.org> | 2014-11-17 17:01:18 +0100 |
commit | 98e3d8faf9eebd382f62a75c886b7e1c6a20279b (patch) | |
tree | 756eb3879157731cb1c2b50f35a744aad8b8796d /strbuf.h | |
parent | ee5a57bc5c5641c30bc626892ddc31ddd18ed7ad (diff) | |
download | git-98e3d8faf9eebd382f62a75c886b7e1c6a20279b.tar.gz git-98e3d8faf9eebd382f62a75c886b7e1c6a20279b.tar.bz2 git-98e3d8faf9eebd382f62a75c886b7e1c6a20279b.zip |
Imported Upstream version 2.0.1upstream/2.0.1
Diffstat (limited to 'strbuf.h')
-rw-r--r-- | strbuf.h | 29 |
1 files changed, 23 insertions, 6 deletions
@@ -17,20 +17,23 @@ extern void strbuf_init(struct strbuf *, size_t); extern void strbuf_release(struct strbuf *); extern char *strbuf_detach(struct strbuf *, size_t *); extern void strbuf_attach(struct strbuf *, void *, size_t, size_t); -static inline void strbuf_swap(struct strbuf *a, struct strbuf *b) { +static inline void strbuf_swap(struct strbuf *a, struct strbuf *b) +{ struct strbuf tmp = *a; *a = *b; *b = tmp; } /*----- strbuf size related -----*/ -static inline size_t strbuf_avail(const struct strbuf *sb) { +static inline size_t strbuf_avail(const struct strbuf *sb) +{ return sb->alloc ? sb->alloc - sb->len - 1 : 0; } extern void strbuf_grow(struct strbuf *, size_t); -static inline void strbuf_setlen(struct strbuf *sb, size_t len) { +static inline void strbuf_setlen(struct strbuf *sb, size_t len) +{ if (len > (sb->alloc ? sb->alloc - 1 : 0)) die("BUG: strbuf_setlen() beyond buffer"); sb->len = len; @@ -97,7 +100,8 @@ static inline struct strbuf **strbuf_split(const struct strbuf *sb, extern void strbuf_list_free(struct strbuf **); /*----- add data in your buffer -----*/ -static inline void strbuf_addch(struct strbuf *sb, int c) { +static inline void strbuf_addch(struct strbuf *sb, int c) +{ strbuf_grow(sb, 1); sb->buf[sb->len++] = c; sb->buf[sb->len] = '\0'; @@ -110,11 +114,15 @@ extern void strbuf_remove(struct strbuf *, size_t pos, size_t len); extern void strbuf_splice(struct strbuf *, size_t pos, size_t len, const void *, size_t); +extern void strbuf_add_commented_lines(struct strbuf *out, const char *buf, size_t size); + extern void strbuf_add(struct strbuf *, const void *, size_t); -static inline void strbuf_addstr(struct strbuf *sb, const char *s) { +static inline void strbuf_addstr(struct strbuf *sb, const char *s) +{ strbuf_add(sb, s, strlen(s)); } -static inline void strbuf_addbuf(struct strbuf *sb, const struct strbuf *sb2) { +static inline void strbuf_addbuf(struct strbuf *sb, const struct strbuf *sb2) +{ strbuf_grow(sb, sb2->len); strbuf_add(sb, sb2->buf, sb2->len); } @@ -131,11 +139,19 @@ extern void strbuf_addbuf_percentquote(struct strbuf *dst, const struct strbuf * __attribute__((format (printf,2,3))) extern void strbuf_addf(struct strbuf *sb, const char *fmt, ...); +__attribute__((format (printf, 2, 3))) +extern void strbuf_commented_addf(struct strbuf *sb, const char *fmt, ...); __attribute__((format (printf,2,0))) extern void strbuf_vaddf(struct strbuf *sb, const char *fmt, va_list ap); extern void strbuf_add_lines(struct strbuf *sb, const char *prefix, const char *buf, size_t size); +/* + * Append s to sb, with the characters '<', '>', '&' and '"' converted + * into XML entities. + */ +extern void strbuf_addstr_xml_quoted(struct strbuf *sb, const char *s); + static inline void strbuf_complete_line(struct strbuf *sb) { if (sb->len && sb->buf[sb->len - 1] != '\n') @@ -160,6 +176,7 @@ extern int strbuf_check_branch_ref(struct strbuf *sb, const char *name); extern void strbuf_addstr_urlencode(struct strbuf *, const char *, int reserved); +extern void strbuf_humanise_bytes(struct strbuf *buf, off_t bytes); __attribute__((format (printf,1,2))) extern int printf_ln(const char *fmt, ...); |