git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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
Previous: René Scharfe
Message 2 of 2 in “convert: use skip_iprefix() in validate_encoding()”
  1. convert: use skip_iprefix() in validate_encoding()René Scharfe, Nov 8, 2019
  2. Jeff KingNov 8, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.