src/common/wchar.c
static int
ucs_wcwidth(pg_wchar ucs)
{
#include "common/unicode_combining_table.h"
#include "common/unicode_east_asian_fw_table.h"

	/* test for 8-bit control characters */
	if (ucs == 0)
		return 0;

	if (ucs < 0x20 || (ucs >= 0x7f && ucs < 0xa0) || ucs > 0x0010ffff)
		return -1;

	/*
	 * binary search in table of non-spacing characters
	 *
	 * XXX: In the official Unicode sources, it is possible for a character to
	 * be described as both non-spacing and wide at the same time. As of
	 * Unicode 13.0, treating the non-spacing property as the determining
	 * factor for display width leads to the correct behavior, so do that
	 * search first.
	 */
	if (mbbisearch(ucs, combining,
				   sizeof(combining) / sizeof(struct mbinterval) - 1))
		return 0;

	/* binary search in table of wide characters */
	if (mbbisearch(ucs, east_asian_fw,
				   sizeof(east_asian_fw) / sizeof(struct mbinterval) - 1))
		return 2;

	return 1;
}
/* The following functions define the column width of an ISO 10646
 * character as follows:
 *
 *	  - The null character (U+0000) has a column width of 0.
 *
 *	  - Other C0/C1 control characters and DEL will lead to a return
 *		value of -1.
 *
 *	  - Non-spacing and enclosing combining characters (general
 *		category code Mn or Me in the Unicode database) have a
 *		column width of 0.
 *
 *	  - Spacing characters in the East Asian Wide (W) or East Asian
 *		FullWidth (F) category as defined in Unicode Technical
 *		Report #11 have a column width of 2.
 *
 *	  - All remaining characters (including all printable
 *		ISO 8859-1 and WGL4 characters, Unicode control characters,
 *		etc.) have a column width of 1.
 *
 * This implementation assumes that wchar_t characters are encoded
 * in ISO 10646.
 */
The following functions define the column width of an ISO 10646
character as follows.

- The null character (U+0000) has a column width of 0.

- Other C0/C1 control characters and DEL will lead to a return
value of -1.

- Non-spacing and enclosing combining characters (general
category code Mn or Me in the Unicode database) have a
column width of 0.

- Spacing characters in the East Asian Wide (W) or East Asian
FullWidth (F) category as defined in Unicode Technical
Report #11 have a column width of 2.

- All remaining characters (including all printable
ISO 8859-1 and WGL4 characters, Unicode control characters,
etc.) have a column width of 1.

This implementation assumes that wchar_t characters are encoded
in ISO 10646.
The following functions define the column width of an ISO 10646 character as follows . - The null character ( U + 0000 ) has a column width of 0 . - Other C0 / C1 control characters and DEL will lead to a return value of - 1 . - Non - spacing and enclosing combining characters ( general category code Mn or Me in the Unicode database ) have a column width of 0 . - Spacing characters in the East Asian Wide ( W ) or East Asian FullWidth ( F ) category as defined in Unicode Technical Report #11 have a column width of 2 . - All remaining characters ( including all printable ISO 8859 - 1 and WGL4 characters Unicode control characters etc . ) have a column width of 1 . This implementation assumes that wchar_t characters are encoded in ISO 10646 .
static int
ucs_wcwidth(pg_wchar ucs)
{
#include "common/unicode_combining_table.h"
#include "common/unicode_east_asian_fw_table.h"
	if (ucs == 0)
		return 0;
	if (ucs < 0x20 || (ucs >= 0x7f && ucs < 0xa0) || ucs > 0x0010ffff)
		return -1;
	if (mbbisearch(ucs, combining,
				   sizeof(combining) / sizeof(struct mbinterval) - 1))
		return 0;
	if (mbbisearch(ucs, east_asian_fw,
				   sizeof(east_asian_fw) / sizeof(struct mbinterval) - 1))
		return 2;
	return 1;
}
static int ucs_wcwidth ( pg_wchar ucs ) { #include " " #include " " if ( ucs == 0 ) return 0 ; if ( ucs < 0x20 || ( ucs >= 0x7f && ucs < 0xa0 ) || ucs > 0x0010ffff ) return -1 ; if ( mbbisearch ( ucs , combining , sizeof ( combining ) / sizeof ( struct mbinterval ) - 1 ) ) return 0 ; if ( mbbisearch ( ucs , east_asian_fw , sizeof ( east_asian_fw ) / sizeof ( struct mbinterval ) - 1 ) ) return 2 ; return 1 ; }
The following functions define the column width of an ISO 10646
 character as follows:
The following functions define the column width of an ISO 10646 character as follows :
/* test for 8-bit control characters */ /*
	 * binary search in table of non-spacing characters
	 *
	 * XXX: In the official Unicode sources, it is possible for a character to
	 * be described as both non-spacing and wide at the same time. As of
	 * Unicode 13.0, treating the non-spacing property as the determining
	 * factor for display width leads to the correct behavior, so do that
	 * search first.
	 */ /* binary search in table of wide characters */