Skip to content

Commit 945c722

Browse files
rscharfegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent da269af commit 945c722

File tree

1 file changed

+6
-18
lines changed

1 file changed

+6
-18
lines changed

strbuf.c

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -996,31 +996,19 @@ void strbuf_addftime(struct strbuf *sb, const char *fmt, const struct tm *tm,
996996
* of seconds.
997997
*/
998998
while (strbuf_expand_step(&munged_fmt, &fmt)) {
999-
switch (*fmt) {
1000-
case '%':
999+
if (skip_prefix(fmt, "%", &fmt))
10011000
strbuf_addstr(&munged_fmt, "%%");
1002-
fmt++;
1003-
break;
1004-
case 's':
1001+
else if (skip_prefix(fmt, "s", &fmt))
10051002
strbuf_addf(&munged_fmt, "%"PRItime,
10061003
(timestamp_t)tm_to_time_t(tm) -
10071004
3600 * (tz_offset / 100) -
10081005
60 * (tz_offset % 100));
1009-
fmt++;
1010-
break;
1011-
case 'z':
1006+
else if (skip_prefix(fmt, "z", &fmt))
10121007
strbuf_addf(&munged_fmt, "%+05d", tz_offset);
1013-
fmt++;
1014-
break;
1015-
case 'Z':
1016-
if (suppress_tz_name) {
1017-
fmt++;
1018-
break;
1019-
}
1020-
/* FALLTHROUGH */
1021-
default:
1008+
else if (suppress_tz_name && skip_prefix(fmt, "Z", &fmt))
1009+
; /* nothing */
1010+
else
10221011
strbuf_addch(&munged_fmt, '%');
1023-
}
10241012
}
10251013
fmt = munged_fmt.buf;
10261014

0 commit comments

Comments
 (0)