ref-filter: introduce parse_align_position()
Extract parse_align_position() from populate_value(), which, given a string, would give us the alignment position. This is a preparatory patch as to introduce prefixes for the %(align) atom and avoid redundancy in the code. Helped-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Karthik Nayak <Karthik.188@gmail.com> Reviewed-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Karthik Nayak committed
Feb 17, 2016 at 23:36 UTC
25a8d79e00f7434676237dc11e8b661c41834650
1 file changed
+15
-6
ref-filter.c
+15
-6
@@ -44,6 +44,17 @@ static void color_atom_parser(struct used_atom *atom, const char *color_value)
44
die(_("unrecognized color: %%(color:%s)"), color_value);
45
}
46
47
+static align_type parse_align_position(const char *s)
48
+{
49
+ if (!strcmp(s, "right"))
50
+ return ALIGN_RIGHT;
51
+ else if (!strcmp(s, "middle"))
52
+ return ALIGN_MIDDLE;
53
+ else if (!strcmp(s, "left"))
54
+ return ALIGN_LEFT;
55
+ return -1;
56
+}
57
+
58
static struct {
59
const char *name;
60
cmp_type cmp_type;
@@ -912,14 +923,12 @@ static void populate_value(struct ref_array_item *ref)
923
string_list_split(¶ms, valp, ',', -1);
924
for (i = 0; i < params.nr; i++) {
925
const char *s = params.items[i].string;
926
+ int position;
927
+
928
if (!strtoul_ui(s, 10, (unsigned int *)&width))
929
;
917
- else if (!strcmp(s, "left"))
918
- align->position = ALIGN_LEFT;
919
- else if (!strcmp(s, "right"))
920
- align->position = ALIGN_RIGHT;
921
- else if (!strcmp(s, "middle"))
922
- align->position = ALIGN_MIDDLE;
930
+ else if ((position = parse_align_position(s)) >= 0)
931
+ align->position = position;
932
else
933
die(_("improper format entered align:%s"), s);
934
}