strbuf: use skip_prefix() in strbuf_addftime()
Use the now common skip_prefix() cascade instead of a case statement to parse the strftime(3) format in strbuf_addftime(). skip_prefix() parses the "fmt" pointer and advances it appropriately, making additional pointer arithmetic unnecessary. The resulting code is more compact and consistent with most other strbuf_expand_step() loops. Signed-off-by: René Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>maint
parent
da269af920
commit
945c72250a
24
strbuf.c
24
strbuf.c
|
@ -996,31 +996,19 @@ void strbuf_addftime(struct strbuf *sb, const char *fmt, const struct tm *tm,
|
||||||
* of seconds.
|
* of seconds.
|
||||||
*/
|
*/
|
||||||
while (strbuf_expand_step(&munged_fmt, &fmt)) {
|
while (strbuf_expand_step(&munged_fmt, &fmt)) {
|
||||||
switch (*fmt) {
|
if (skip_prefix(fmt, "%", &fmt))
|
||||||
case '%':
|
|
||||||
strbuf_addstr(&munged_fmt, "%%");
|
strbuf_addstr(&munged_fmt, "%%");
|
||||||
fmt++;
|
else if (skip_prefix(fmt, "s", &fmt))
|
||||||
break;
|
|
||||||
case 's':
|
|
||||||
strbuf_addf(&munged_fmt, "%"PRItime,
|
strbuf_addf(&munged_fmt, "%"PRItime,
|
||||||
(timestamp_t)tm_to_time_t(tm) -
|
(timestamp_t)tm_to_time_t(tm) -
|
||||||
3600 * (tz_offset / 100) -
|
3600 * (tz_offset / 100) -
|
||||||
60 * (tz_offset % 100));
|
60 * (tz_offset % 100));
|
||||||
fmt++;
|
else if (skip_prefix(fmt, "z", &fmt))
|
||||||
break;
|
|
||||||
case 'z':
|
|
||||||
strbuf_addf(&munged_fmt, "%+05d", tz_offset);
|
strbuf_addf(&munged_fmt, "%+05d", tz_offset);
|
||||||
fmt++;
|
else if (suppress_tz_name && skip_prefix(fmt, "Z", &fmt))
|
||||||
break;
|
; /* nothing */
|
||||||
case 'Z':
|
else
|
||||||
if (suppress_tz_name) {
|
|
||||||
fmt++;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
/* FALLTHROUGH */
|
|
||||||
default:
|
|
||||||
strbuf_addch(&munged_fmt, '%');
|
strbuf_addch(&munged_fmt, '%');
|
||||||
}
|
|
||||||
}
|
}
|
||||||
fmt = munged_fmt.buf;
|
fmt = munged_fmt.buf;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue