Re: [PATCH v4 2/2] diff.c: More changes and tests around utf8_strwidth()
- From
Johannes Schindelin <johannes.schindelin@gmx.de>
- Date
- Sep 5, 2022, 10:13 UTC
- Message-ID
- <772s47o8-o5r2-0s9p-5681-9ooo9r144p57@tzk.qr>
- In-Reply-To
- <20220903053934.15629-1-tboegi@web.de>
Hi Torsten,
thank you for working on a new iteration!
On Sat, 3 Sep 2022, tboegi@web.de wrote:
Show 11 quoted lines
> [...] > diff --git a/diff.c b/diff.c > index b5df464de5..35b9da90fe 100644 > --- a/diff.c > +++ b/diff.c > @@ -2734,7 +2734,7 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options) > char *name = file->print_name; > uintmax_t added = file->added; > uintmax_t deleted = file->deleted; > - int name_len; > + int name_len, padding;
I had a look and `len` is also declard as an `int`.
Show 10 quoted lines
> > if (!file->is_interesting && (added + deleted == 0)) > continue; > @@ -2753,10 +2753,14 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options) > if (slash) > name = slash; > } > + padding = len - utf8_strwidth(name); > + if (padding < 0) > + padding = 0;
I would have had a slight preference for something like this:
int name_len = utf8_strwidth(name); int padding = name_len < len ? len - name_len : 0;
i.e. avoid the potentially negative difference. (Ideally, I would have liked the type to be changed to `size_t`, but that is impractical due to the variables' use in `%.*s` formats.)
But it is not worth a new iteration on its own, and I am very happy with the current iteration.
Thanks! Dscho