diff options
Diffstat (limited to 'strbuf.h')
-rw-r--r-- | strbuf.h | 63 |
1 files changed, 52 insertions, 11 deletions
@@ -44,22 +44,56 @@ extern void strbuf_rtrim(struct strbuf *); extern void strbuf_ltrim(struct strbuf *); extern int strbuf_cmp(const struct strbuf *, const struct strbuf *); +/* + * Split str (of length slen) at the specified terminator character. + * Return a null-terminated array of pointers to strbuf objects + * holding the substrings. The substrings include the terminator, + * except for the last substring, which might be unterminated if the + * original string did not end with a terminator. If max is positive, + * then split the string into at most max substrings (with the last + * substring containing everything following the (max-1)th terminator + * character). + * + * For lighter-weight alternatives, see string_list_split() and + * string_list_split_in_place(). + */ extern struct strbuf **strbuf_split_buf(const char *, size_t, - int delim, int max); + int terminator, int max); + +/* + * Split a NUL-terminated string at the specified terminator + * character. See strbuf_split_buf() for more information. + */ static inline struct strbuf **strbuf_split_str(const char *str, - int delim, int max) + int terminator, int max) { - return strbuf_split_buf(str, strlen(str), delim, max); + return strbuf_split_buf(str, strlen(str), terminator, max); } + +/* + * Split a strbuf at the specified terminator character. See + * strbuf_split_buf() for more information. + */ static inline struct strbuf **strbuf_split_max(const struct strbuf *sb, - int delim, int max) + int terminator, int max) { - return strbuf_split_buf(sb->buf, sb->len, delim, max); + return strbuf_split_buf(sb->buf, sb->len, terminator, max); } -static inline struct strbuf **strbuf_split(const struct strbuf *sb, int delim) + +/* + * Split a strbuf at the specified terminator character. See + * strbuf_split_buf() for more information. + */ +static inline struct strbuf **strbuf_split(const struct strbuf *sb, + int terminator) { - return strbuf_split_max(sb, delim, 0); + return strbuf_split_max(sb, terminator, 0); } + +/* + * Free a NULL-terminated list of strbufs (for example, the return + * values of the strbuf_split*() functions). + */ extern void strbuf_list_free(struct strbuf **); /*----- add data in your buffer -----*/ @@ -76,6 +110,8 @@ 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) { strbuf_add(sb, s, strlen(s)); @@ -97,13 +133,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); -__attribute__((format (printf,2,3))) -extern void strbuf_addf_ln(struct strbuf *sb, const char *fmt, ...); 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') @@ -126,10 +168,9 @@ extern int launch_editor(const char *path, struct strbuf *buffer, const char *co extern int strbuf_branchname(struct strbuf *sb, const char *name); extern int strbuf_check_branch_ref(struct strbuf *sb, const char *name); -extern void strbuf_add_urlencode(struct strbuf *, const char *, size_t, - int reserved); 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, ...); |