diff options
author | René Scharfe <l.s.r@web.de> | 2016-09-03 17:59:20 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2016-09-07 10:42:46 -0700 |
commit | d23309733a5b2a9e1adc304ee50c5a5ed7a087c2 (patch) | |
tree | c1555e8fce5bdf708b48fb43391c98002dcd3716 /ref-filter.c | |
parent | Git 2.9.3 (diff) | |
download | tgif-d23309733a5b2a9e1adc304ee50c5a5ed7a087c2.tar.xz |
introduce hex2chr() for converting two hexadecimal digits to a character
Add and use a helper function that decodes the char value of two
hexadecimal digits. It returns a negative number on error, avoids
running over the end of the given string and doesn't shift negative
values.
Signed-off-by: Rene Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'ref-filter.c')
-rw-r--r-- | ref-filter.c | 20 |
1 files changed, 1 insertions, 19 deletions
diff --git a/ref-filter.c b/ref-filter.c index bc551a752c..9adbb8af3e 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -1576,24 +1576,6 @@ void ref_array_sort(struct ref_sorting *sorting, struct ref_array *array) qsort(array->items, array->nr, sizeof(struct ref_array_item *), compare_refs); } -static int hex1(char ch) -{ - if ('0' <= ch && ch <= '9') - return ch - '0'; - else if ('a' <= ch && ch <= 'f') - return ch - 'a' + 10; - else if ('A' <= ch && ch <= 'F') - return ch - 'A' + 10; - return -1; -} -static int hex2(const char *cp) -{ - if (cp[0] && cp[1]) - return (hex1(cp[0]) << 4) | hex1(cp[1]); - else - return -1; -} - static void append_literal(const char *cp, const char *ep, struct ref_formatting_state *state) { struct strbuf *s = &state->stack->output; @@ -1603,7 +1585,7 @@ static void append_literal(const char *cp, const char *ep, struct ref_formatting if (cp[1] == '%') cp++; else { - int ch = hex2(cp + 1); + int ch = hex2chr(cp + 1); if (0 <= ch) { strbuf_addch(s, ch); cp += 3; |