diff mbox series

[v2,1/5] mailinfo: avoid magic number in option parsing

Message ID e1e0d8196197d0eb3a39454a48b112a5843d33d7.1620148732.git.congdanhqx@gmail.com (mailing list archive)
State Superseded
Headers show
Series Teach am/mailinfo to process quoted CR | expand

Commit Message

Đoàn Trần Công Danh May 4, 2021, 5:19 p.m. UTC
While current magic number is perfectly correct, in a later change,
we would like to parse for another option, namely "--quoted-cr".
Let's refactor a bit to remove that magic number.

Signed-off-by: Đoàn Trần Công Danh <congdanhqx@gmail.com>
---
 builtin/mailinfo.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/builtin/mailinfo.c b/builtin/mailinfo.c
index cfb667a594..b309badce5 100644
--- a/builtin/mailinfo.c
+++ b/builtin/mailinfo.c
@@ -24,6 +24,7 @@  int cmd_mailinfo(int argc, const char **argv, const char *prefix)
 	mi.metainfo_charset = def_charset;
 
 	while (1 < argc && argv[1][0] == '-') {
+		const char *str;
 		if (!strcmp(argv[1], "-k"))
 			mi.keep_subject = 1;
 		else if (!strcmp(argv[1], "-b"))
@@ -34,8 +35,8 @@  int cmd_mailinfo(int argc, const char **argv, const char *prefix)
 			mi.metainfo_charset = def_charset;
 		else if (!strcmp(argv[1], "-n"))
 			mi.metainfo_charset = NULL;
-		else if (starts_with(argv[1], "--encoding="))
-			mi.metainfo_charset = argv[1] + 11;
+		else if (skip_prefix(argv[1], "--encoding=", &str))
+			mi.metainfo_charset = str;
 		else if (!strcmp(argv[1], "--scissors"))
 			mi.use_scissors = 1;
 		else if (!strcmp(argv[1], "--no-scissors"))