strbuf_split*(): rename "delim" parameter to "terminator"

The word "delimiter" suggests that the argument separates the substrings, whereas in fact (1) the delimiter characters are included in the output, and (2) if the input string ends with the delimiter, then the output does not include a final empty string. So rename the "delim" arguments of the strbuf_split() family of functions to "terminator", which is more suggestive of how it is used. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Jeff King <peff@peff.net>

Michael Haggerty committed Nov 4, 2012 at 07:46 UTC 17b73dc699c46d7af5d29d2f3813e7addafdce0d
2 files changed +11 -9
strbuf.c
+3 -2
@@ -106,7 +106,8 @@ void strbuf_ltrim(struct strbuf *sb)
106 sb->buf[sb->len] = '\0';
107 }
108
109 -struct strbuf **strbuf_split_buf(const char *str, size_t slen, int delim, int max)
109 +struct strbuf **strbuf_split_buf(const char *str, size_t slen,
110 + int terminator, int max)
111 {
112 struct strbuf **ret = NULL;
113 size_t nr = 0, alloc = 0;
@@ -115,7 +116,7 @@ struct strbuf **strbuf_split_buf(const char *str, size_t slen, int delim, int ma
116 while (slen) {
117 int len = slen;
118 if (max <= 0 || nr + 1 < max) {
118 - const char *end = memchr(str, delim, slen);
119 + const char *end = memchr(str, terminator, slen);
120 if (end)
121 len = end - str + 1;
122 }
strbuf.h
+8 -7
@@ -45,20 +45,21 @@ extern void strbuf_ltrim(struct strbuf *);
45 extern int strbuf_cmp(const struct strbuf *, const struct strbuf *);
46
47 extern struct strbuf **strbuf_split_buf(const char *, size_t,
48 - int delim, int max);
48 + int terminator, int max);
49 static inline struct strbuf **strbuf_split_str(const char *str,
50 - int delim, int max)
50 + int terminator, int max)
51 {
52 - return strbuf_split_buf(str, strlen(str), delim, max);
52 + return strbuf_split_buf(str, strlen(str), terminator, max);
53 }
54 static inline struct strbuf **strbuf_split_max(const struct strbuf *sb,
55 - int delim, int max)
55 + int terminator, int max)
56 {
57 - return strbuf_split_buf(sb->buf, sb->len, delim, max);
57 + return strbuf_split_buf(sb->buf, sb->len, terminator, max);
58 }
59 -static inline struct strbuf **strbuf_split(const struct strbuf *sb, int delim)
59 +static inline struct strbuf **strbuf_split(const struct strbuf *sb,
60 + int terminator)
61 {
61 - return strbuf_split_max(sb, delim, 0);
62 + return strbuf_split_max(sb, terminator, 0);
63 }
64 extern void strbuf_list_free(struct strbuf **);
65