Skip to content

Commit 89f8cab

Browse files
rscharfegitster
authored andcommitted
utf8: use skip_iprefix() in same_utf_encoding()
Get rid of magic numbers by using skip_iprefix() and skip_prefix() for parsing the leading "[uU][tT][fF]-?" of both strings instead of checking with istarts_with() and an explicit comparison. Signed-off-by: René Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent da72936 commit 89f8cab

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

Diff for: utf8.c

+4-5
Original file line numberDiff line numberDiff line change
@@ -411,11 +411,10 @@ void strbuf_utf8_replace(struct strbuf *sb_src, int pos, int width,
411411
*/
412412
static int same_utf_encoding(const char *src, const char *dst)
413413
{
414-
if (istarts_with(src, "utf") && istarts_with(dst, "utf")) {
415-
/* src[3] or dst[3] might be '\0' */
416-
int i = (src[3] == '-' ? 4 : 3);
417-
int j = (dst[3] == '-' ? 4 : 3);
418-
return !strcasecmp(src+i, dst+j);
414+
if (skip_iprefix(src, "utf", &src) && skip_iprefix(dst, "utf", &dst)) {
415+
skip_prefix(src, "-", &src);
416+
skip_prefix(dst, "-", &dst);
417+
return !strcasecmp(src, dst);
419418
}
420419
return 0;
421420
}

0 commit comments

Comments
 (0)