From: Junio C Hamano <gitster@pobox.com>
To: Patrick Steinhardt <ps@pks.im>
Cc: Chandra Pratap via GitGitGadget <gitgitgadget@gmail.com>,
git@vger.kernel.org, Chandra Pratap <chandrapratap376@gmail.com>,
Chandra Pratap <chandrapratap3519@gmail.com>
Subject: Re: [PATCH] diff.c: use utf8_strwidth() instead of strlen() for display width
Date: Sun, 18 Feb 2024 23:01:24 -0800 [thread overview]
Message-ID: <xmqqh6i5ey4b.fsf@gitster.g> (raw)
In-Reply-To: <ZdLzxYpY-klokgpI@tanuki> (Patrick Steinhardt's message of "Mon, 19 Feb 2024 07:23:01 +0100")
Patrick Steinhardt <ps@pks.im> writes:
> 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?"
prev parent reply other threads:[~2024-02-19 7:01 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-18 18:37 [PATCH] diff.c: use utf8_strwidth() instead of strlen() for display width Chandra Pratap via GitGitGadget
2024-02-19 6:23 ` Patrick Steinhardt
2024-02-19 7:01 ` Junio C Hamano [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqh6i5ey4b.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=chandrapratap3519@gmail.com \
--cc=chandrapratap376@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--cc=ps@pks.im \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).