Skip to content

Commit 02f50d0

Browse files
committed
Merge branch 'rs/strbuf-addftime-simplify'
Code clean-up. * rs/strbuf-addftime-simplify: strbuf: use skip_prefix() in strbuf_addftime()
2 parents 261ff51 + 945c722 commit 02f50d0

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
@@ -936,31 +936,19 @@ void strbuf_addftime(struct strbuf *sb, const char *fmt, const struct tm *tm,
936936
* of seconds.
937937
*/
938938
while (strbuf_expand_step(&munged_fmt, &fmt)) {
939-
switch (*fmt) {
940-
case '%':
939+
if (skip_prefix(fmt, "%", &fmt))
941940
strbuf_addstr(&munged_fmt, "%%");
942-
fmt++;
943-
break;
944-
case 's':
941+
else if (skip_prefix(fmt, "s", &fmt))
945942
strbuf_addf(&munged_fmt, "%"PRItime,
946943
(timestamp_t)tm_to_time_t(tm) -
947944
3600 * (tz_offset / 100) -
948945
60 * (tz_offset % 100));
949-
fmt++;
950-
break;
951-
case 'z':
946+
else if (skip_prefix(fmt, "z", &fmt))
952947
strbuf_addf(&munged_fmt, "%+05d", tz_offset);
953-
fmt++;
954-
break;
955-
case 'Z':
956-
if (suppress_tz_name) {
957-
fmt++;
958-
break;
959-
}
960-
/* FALLTHROUGH */
961-
default:
948+
else if (suppress_tz_name && skip_prefix(fmt, "Z", &fmt))
949+
; /* nothing */
950+
else
962951
strbuf_addch(&munged_fmt, '%');
963-
}
964952
}
965953
fmt = munged_fmt.buf;
966954

0 commit comments

Comments
 (0)