summaryrefslogtreecommitdiff
path: root/src/common/wchar.c
diff options
context:
space:
mode:
authorJohn Naylor2021-08-26 13:58:28 +0000
committerJohn Naylor2021-08-26 13:58:28 +0000
commitf8c8a8bccc23f6ca38f7a92c9a614e73fa1fcfb6 (patch)
treea04dae626dd5a0aea99142bc63cb86e66130521a /src/common/wchar.c
parent0d906b2c0b1f0d625ff63d9ace906556b1c66a68 (diff)
Revert "Change mbbisearch to return the character range"
This reverts commit 78ab944cd4b9977732becd9d0bc83223b88af9a2. After I had committed eb0d0d2c7 and 78ab944cd, I decided to add a sanity check for a "can't happen" scenario just to be cautious. It turned out that it already happened in the official Unicode source data, namely that a character can be both wide and a combining character. This fact renders the aforementioned commits unnecessary, so revert both of them. Discussion: https://www.postgresql.org/message-id/CAFBsxsH5ejH4-1xaTLpSK8vWoK1m6fA1JBtTM6jmBsLfmDki1g%40mail.gmail.com
Diffstat (limited to 'src/common/wchar.c')
-rw-r--r--src/common/wchar.c21
1 files changed, 8 insertions, 13 deletions
diff --git a/src/common/wchar.c b/src/common/wchar.c
index 8242bcd3873..bb97b5f54f4 100644
--- a/src/common/wchar.c
+++ b/src/common/wchar.c
@@ -585,18 +585,17 @@ struct mbinterval
{
unsigned short first;
unsigned short last;
- signed int width;
};
/* auxiliary function for binary search in interval table */
-static const struct mbinterval *
+static int
mbbisearch(pg_wchar ucs, const struct mbinterval *table, int max)
{
int min = 0;
int mid;
if (ucs < table[0].first || ucs > table[max].last)
- return NULL;
+ return 0;
while (max >= min)
{
mid = (min + max) / 2;
@@ -605,10 +604,10 @@ mbbisearch(pg_wchar ucs, const struct mbinterval *table, int max)
else if (ucs < table[mid].first)
max = mid - 1;
else
- return &table[mid];
+ return 1;
}
- return NULL;
+ return 0;
}
@@ -647,8 +646,6 @@ ucs_wcwidth(pg_wchar ucs)
{
#include "common/unicode_width_table.h"
- const struct mbinterval *range;
-
/* test for 8-bit control characters */
if (ucs == 0)
return 0;
@@ -656,12 +653,10 @@ ucs_wcwidth(pg_wchar ucs)
if (ucs < 0x20 || (ucs >= 0x7f && ucs < 0xa0) || ucs > 0x0010ffff)
return -1;
- /* binary search in table of character widths */
- range = mbbisearch(ucs, wcwidth,
- sizeof(wcwidth) / sizeof(struct mbinterval) - 1);
-
- if (range != NULL)
- return range->width;
+ /* binary search in table of non-spacing characters */
+ if (mbbisearch(ucs, combining,
+ sizeof(combining) / sizeof(struct mbinterval) - 1))
+ return 0;
/*
* if we arrive here, ucs is not a combining or C0/C1 control character