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

Re: [PATCH] diff.c: use utf8_strwidth() instead of strlen() for display width

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 19, 2024, 07:01 UTC
Message-ID
<xmqqh6i5ey4b.fsf@gitster.g>
In-Reply-To
<ZdLzxYpY-klokgpI@tanuki>
Patrick Steinhardt <ps@pks.im> writes:
Show 5 quoted lines
> Also, do you know why we didn't use `utf8_strwidth()` right from the
> start? It would have saved the writer some time to just use
> `utf8_strwidth()` instead of writing a whole paragraph explaining that
> we should do it eventually. Makes me wonder whether there is anything
> else going on here.

I suspect that it is because it is not just that single strlen() call. The code assumed that byte count and display width were interchangeable, and use of strlen() there was merely an example. Starting there, the value returned by strlen() is treated as if it were interchangeable with a display width, and then later used to count how many bytes to trim from either end of the string so that the trimmed string would eventually fit a given display width, which means that the code to compute how much to trim (which is not that strlen() the patch in question is touching) would have to compute the reverse, i.e. "if we need to recover N display columns, how many bytes do we need to trim from that string?"

Previous: Patrick Steinhardt
Message 3 of 3 in “diff.c: use utf8_strwidth() instead of strlen() for display width”
  1. diff.c: use utf8_strwidth() instead of strlen() for display widthChandra Pratap via GitGitGadget, Feb 18, 2024
  2. Patrick SteinhardtFeb 19, 2024
  3. Junio C HamanoFeb 19, 2024

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.