@matheusbsbs / matheus-bagliano / commits / 89f8cabaf3
Fork 0

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 <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Nov 8, 2019 at 21:25 UTC 89f8cabaf35f8a5f7e893f190764597ad5c44ef9
1 file changed +4 -5
utf8.c
+4 -5
@@ -411,11 +411,10 @@ out:
411 */
412 static int same_utf_encoding(const char *src, const char *dst)
413 {
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);
418 }
419 return 0;
420 }