strbuf: add strbuf_tolower function
This is a convenience wrapper to call tolower on each character of the string. This makes config's lowercase() function obsolete, though note that because we have a strbuf, we are careful to operate over the whole strbuf, rather than assuming that a NUL is the end-of-string. We could continue to offer a pure-string lowercase, but there would be no callers (in most pure-string cases, we actually duplicate and lowercase the duplicate, for which we have the xstrdup_tolower wrapper). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
May 23, 2014 at 16:03 UTC
ffb20ce125f0ffe59002b1258b06c26747b69b7b
4 files changed
+13
-7
Documentation/technical/api-strbuf.txt
+4
@@ -125,6 +125,10 @@ Functions
125
126
Strip whitespace from the end of a string.
127
128
+`strbuf_tolower`::
129
+
130
+ Lowercase each character in the buffer using `tolower`.
131
+
132
`strbuf_cmp`::
133
134
Compare two buffers. Returns an integer less than, equal to, or greater
config.c
+1
-7
@@ -147,12 +147,6 @@ int git_config_include(const char *var, const char *value, void *data)
147
return ret;
148
}
149
150
-static void lowercase(char *p)
151
-{
152
- for (; *p; p++)
153
- *p = tolower(*p);
154
-}
155
-
150
void git_config_push_parameter(const char *text)
151
{
152
struct strbuf env = STRBUF_INIT;
@@ -180,7 +174,7 @@ int git_config_parse_parameter(const char *text,
174
strbuf_list_free(pair);
175
return error("bogus config parameter: %s", text);
176
}
183
- lowercase(pair[0]->buf);
177
+ strbuf_tolower(pair[0]);
178
if (fn(pair[0]->buf, pair[1] ? pair[1]->buf : NULL, data) < 0) {
179
strbuf_list_free(pair);
180
return -1;
strbuf.c
+7
@@ -106,6 +106,13 @@ void strbuf_ltrim(struct strbuf *sb)
106
sb->buf[sb->len] = '\0';
107
}
108
109
+void strbuf_tolower(struct strbuf *sb)
110
+{
111
+ char *p = sb->buf, *end = sb->buf + sb->len;
112
+ for (; p < end; p++)
113
+ *p = tolower(*p);
114
+}
115
+
116
struct strbuf **strbuf_split_buf(const char *str, size_t slen,
117
int terminator, int max)
118
{
strbuf.h
+1
@@ -45,6 +45,7 @@ static inline void strbuf_setlen(struct strbuf *sb, size_t len)
45
extern void strbuf_trim(struct strbuf *);
46
extern void strbuf_rtrim(struct strbuf *);
47
extern void strbuf_ltrim(struct strbuf *);
48
+extern void strbuf_tolower(struct strbuf *sb);
49
extern int strbuf_cmp(const struct strbuf *, const struct strbuf *);
50
51
/*