I wrote:
> Actually, looking at the comments for ucs_wcwidth() in wchar.c, it seems
> that this is already accounted for in the "dsplen" output: characters
> for which -1 is returned are control characters, characters for which
> 0 is returned should be printed as-is and counted as zero width. So the
> bug is just that pg_wcsformat conflates the two cases.
I've applied the attached patch to fix this, but not being much of a
user of languages that have combining characters, I can't test it very
well. Please check out the behavior and see if you like it.
regards, tom lane