1
0
mirror of https://github.com/postgres/postgres.git synced 2025-10-24 01:29:19 +03:00

Introduce t_isalnum() to replace t_isalpha() || t_isdigit() tests.

ts_locale.c omitted support for "isalnum" tests, perhaps on the
grounds that there were initially no use-cases for that.  However,
both ltree and pg_trgm need such tests, and we do also have one
use-case now in the core backend.  The workaround of testing
isalpha and isdigit separately seems quite inefficient, especially
when dealing with multibyte characters; so let's fill in the
missing support.

Discussion: https://postgr.es/m/2548310.1664999615@sss.pgh.pa.us
This commit is contained in:
Tom Lane
2022-10-06 11:08:56 -04:00
parent 5757141cae
commit ca71131eeb
5 changed files with 20 additions and 3 deletions

View File

@@ -81,6 +81,22 @@ t_isalpha(const char *ptr)
return iswalpha((wint_t) character[0]);
}
int
t_isalnum(const char *ptr)
{
int clen = pg_mblen(ptr);
wchar_t character[WC_BUF_LEN];
Oid collation = DEFAULT_COLLATION_OID; /* TODO */
pg_locale_t mylocale = 0; /* TODO */
if (clen == 1 || lc_ctype_is_c(collation))
return isalnum(TOUCHAR(ptr));
char2wchar(character, WC_BUF_LEN, ptr, clen, mylocale);
return iswalnum((wint_t) character[0]);
}
int
t_isprint(const char *ptr)
{