Thread (1 message) 1 message, 1 author, 2017-03-21

Re: [PATCH] rev-parse: match @{u}, @{push} and ^{<type>} case-insensitively

From: Junio C Hamano <hidden>
Date: 2017-03-21 19:27:30

Ævar Arnfjörð Bjarmason [off-list ref] writes:
On Sat, Mar 18, 2017 at 11:34 PM, Ævar Arnfjörð Bjarmason
[off-list ref] wrote:
quoted
The new starts_with_case() function is a copy of the existing adjacent
starts_with(), just with a tolower() in the "else if".
[...]
+int starts_with_case(const char *str, const char *prefix)
+{
+       for (; ; str++, prefix++)
+               if (!*prefix)
+                       return 1;
+               else if (tolower(*str) != tolower(*prefix))
+                       return 0;
+}
+
 /*
One thing I'd like feedback on is whether I should be adding this to
strbuf.c. There are >300 uses of starts_with(), but sha1_name.c will
be the only one using this modified starts_with_case() function.
Wouldn't it be better to just add it to sha1_name.c rather than
expanding the strbuf API with something that'll likely be used by
nothing else for a while?
Yeah, static inside sha1_name.c is OK; people with newer needs can
move it later if necessary.

I'd have called starts_with_icase(), though.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help