]> git.ipfire.org Git - thirdparty/git.git/commitdiff
strbuf: use skip_prefix() in strbuf_addftime()
authorRené Scharfe <l.s.r@web.de>
Sun, 16 Jul 2023 08:52:33 +0000 (10:52 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 17 Jul 2023 16:24:49 +0000 (09:24 -0700)
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>
strbuf.c

index bfa14385432909a3cecd054e8063da39d501be7b..ccb9b4dc948ef4495b5d360f3fea1628abb448b2 100644 (file)
--- a/strbuf.c
+++ b/strbuf.c
@@ -996,31 +996,19 @@ void strbuf_addftime(struct strbuf *sb, const char *fmt, const struct tm *tm,
         * of seconds.
         */
        while (strbuf_expand_step(&munged_fmt, &fmt)) {
-               switch (*fmt) {
-               case '%':
+               if (skip_prefix(fmt, "%", &fmt))
                        strbuf_addstr(&munged_fmt, "%%");
-                       fmt++;
-                       break;
-               case 's':
+               else if (skip_prefix(fmt, "s", &fmt))
                        strbuf_addf(&munged_fmt, "%"PRItime,
                                    (timestamp_t)tm_to_time_t(tm) -
                                    3600 * (tz_offset / 100) -
                                    60 * (tz_offset % 100));
-                       fmt++;
-                       break;
-               case 'z':
+               else if (skip_prefix(fmt, "z", &fmt))
                        strbuf_addf(&munged_fmt, "%+05d", tz_offset);
-                       fmt++;
-                       break;
-               case 'Z':
-                       if (suppress_tz_name) {
-                               fmt++;
-                               break;
-                       }
-                       /* FALLTHROUGH */
-               default:
+               else if (suppress_tz_name && skip_prefix(fmt, "Z", &fmt))
+                       ; /* nothing */
+               else
                        strbuf_addch(&munged_fmt, '%');
-               }
        }
        fmt = munged_fmt.buf;