Re: badly calculated width of emoji in psql

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: badly calculated width of emoji in psql
Date: 2021-04-02 09:51:26
Message-ID: CAFj8pRDuNNPJ-Xzd8ZC3dF4pbOsAZAH-zbA0Y65uivTZ2zT1ZQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

pá 2. 4. 2021 v 11:37 odesílatel Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
napsal:

> On Fri, 2021-04-02 at 10:45 +0200, Pavel Stehule wrote:
> > I am checked an query from
> https://www.depesz.com/2021/04/01/waiting-for-postgresql-14-add-unistr-function/
> article.
> >
> > postgres=# SELECT U&'\+01F603';
> > ┌──────────┐
> > │ ?column? │
> > ╞══════════╡
> > │ 😃 │
> > └──────────┘
> > (1 row)
> >
> >
> > The result is not correct. Emoji has width 2 chars, but psql calculates
> with just one char.
>
> How about this:
>
> diff --git a/src/common/wchar.c b/src/common/wchar.c
> index 6e7d731e02..e2d0d9691c 100644
> --- a/src/common/wchar.c
> +++ b/src/common/wchar.c
> @@ -673,7 +673,8 @@ ucs_wcwidth(pg_wchar ucs)
> (ucs >= 0xfe30 && ucs <= 0xfe6f) || /* CJK
> Compatibility Forms */
> (ucs >= 0xff00 && ucs <= 0xff5f) || /* Fullwidth Forms
> */
> (ucs >= 0xffe0 && ucs <= 0xffe6) ||
> - (ucs >= 0x20000 && ucs <= 0x2ffff)));
> + (ucs >= 0x20000 && ucs <= 0x2ffff) ||
> + (ucs >= 0x1f300 && ucs <= 0x1faff))); /* symbols and
> emojis */
> }
>
> /*
>
> This is guesswork based on the unicode entries that look like symbols.
>

it helps

with this patch, the formatting is correct

Pavel

>
> Yours,
> Laurenz Albe
>
>

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2021-04-02 09:59:31 Re: Fix pg_checksums progress report
Previous Message 蔡梦娟 (玊于) 2021-04-02 09:41:33 Why reset pgstat during recovery