{"thread":{"id":"59993","subject":"[PATCH] strbuf: use skip_prefix() in strbuf_addftime()","startedAt":"2023-07-16T08:52:38Z","lastAt":"2023-07-16T08:52:38Z","messageCount":1,"participants":["René Scharfe"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"479558","messageId":"fccba24c-584d-6329-69a7-75cf0458af7d@web.de","threadId":"59993","inReplyTo":null,"subject":"[PATCH] strbuf: use skip_prefix() in strbuf_addftime()","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2023-07-16T08:52:33Z","receivedAt":"2023-07-16T08:52:38Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Use the now common skip_prefix() cascade instead of a case statement to\nparse the strftime(3) format in strbuf_addftime().  skip_prefix() parses\nthe \"fmt\" pointer and advances it appropriately, making additional\npointer arithmetic unnecessary.  The resulting code is more compact and\nconsistent with most other strbuf_expand_step() loops.\n\nSigned-off-by: René Scharfe <l.s.r@web.de>\n---\n strbuf.c | 24 ++++++------------------\n 1 file changed, 6 insertions(+), 18 deletions(-)\n\ndiff --git a/strbuf.c b/strbuf.c\nindex 399242684b..837975ef9c 100644\n--- a/strbuf.c\n+++ b/strbuf.c\n@@ -935,31 +935,19 @@ void strbuf_addftime(struct strbuf *sb, const char *fmt, const struct tm *tm,\n \t * of seconds.\n \t */\n \twhile (strbuf_expand_step(&munged_fmt, &fmt)) {\n-\t\tswitch (*fmt) {\n-\t\tcase '%':\n+\t\tif (skip_prefix(fmt, \"%\", &fmt))\n \t\t\tstrbuf_addstr(&munged_fmt, \"%%\");\n-\t\t\tfmt++;\n-\t\t\tbreak;\n-\t\tcase 's':\n+\t\telse if (skip_prefix(fmt, \"s\", &fmt))\n \t\t\tstrbuf_addf(&munged_fmt, \"%\"PRItime,\n \t\t\t\t    (timestamp_t)tm_to_time_t(tm) -\n \t\t\t\t    3600 * (tz_offset / 100) -\n \t\t\t\t    60 * (tz_offset % 100));\n-\t\t\tfmt++;\n-\t\t\tbreak;\n-\t\tcase 'z':\n+\t\telse if (skip_prefix(fmt, \"z\", &fmt))\n \t\t\tstrbuf_addf(&munged_fmt, \"%+05d\", tz_offset);\n-\t\t\tfmt++;\n-\t\t\tbreak;\n-\t\tcase 'Z':\n-\t\t\tif (suppress_tz_name) {\n-\t\t\t\tfmt++;\n-\t\t\t\tbreak;\n-\t\t\t}\n-\t\t\t/* FALLTHROUGH */\n-\t\tdefault:\n+\t\telse if (suppress_tz_name && skip_prefix(fmt, \"Z\", &fmt))\n+\t\t\t; /* nothing */\n+\t\telse\n \t\t\tstrbuf_addch(&munged_fmt, '%');\n-\t\t}\n \t}\n \tfmt = munged_fmt.buf;\n\n--\n2.41.0\n\n"}]}