Re: [PATCH] convert: use skip_iprefix() in validate_encoding()
- From
Jeff King <peff@peff.net>
- Date
- Nov 8, 2019, 22:19 UTC
- Message-ID
- <20191108221949.GA18519@sigill.intra.peff.net>
- In-Reply-To
- <a61b60e4-77f4-10a9-65ff-f78348d4c4b7@web.de>
On Fri, Nov 08, 2019 at 09:27:34PM +0100, René Scharfe wrote:
Show 16 quoted lines
> @@ -285,15 +289,10 @@ static int validate_encoding(const char *path, const char *enc,
> */
> const char *advise_msg = _(
> "The file '%s' contains a byte order "
> - "mark (BOM). Please use UTF-%s as "
> + "mark (BOM). Please use UTF-%.*s as "
> "working-tree-encoding.");
> - const char *stripped = NULL;
> - char *upper = xstrdup_toupper(enc);
> - upper[strlen(upper)-2] = '\0';
> - if (skip_prefix(upper, "UTF", &stripped))
> - skip_prefix(stripped, "-", &stripped);
> - advise(advise_msg, path, stripped);
> - free(upper);
> + int stripped_len = strlen(stripped) - strlen("BE");
> + advise(advise_msg, path, stripped_len, stripped);I think we could drop xstrdup_toupper() after this.
Of course it _could_ come in handy in another spot, but in most cases you can use xstrdup_tolower() interchangeably (e.g., that would have worked here). And even the tolower() variant is seldom used.
-Peff