Skip to content

Commit ca71131

Browse files
committed
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
1 parent 5757141 commit ca71131

File tree

5 files changed

+20
-3
lines changed

5 files changed

+20
-3
lines changed

contrib/ltree/ltree.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ typedef struct
126126

127127
#define LQUERY_HASNOT 0x01
128128

129-
#define ISALNUM(x) ( t_isalpha(x) || t_isdigit(x) || ( pg_mblen(x) == 1 && t_iseq((x), '_') ) )
129+
#define ISALNUM(x) ( t_isalnum(x) || ( pg_mblen(x) == 1 && t_iseq((x), '_') ) )
130130

131131
/* full text query */
132132

contrib/pg_trgm/trgm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ typedef char trgm[3];
5252
} while(0)
5353

5454
#ifdef KEEPONLYALNUM
55-
#define ISWORDCHR(c) (t_isalpha(c) || t_isdigit(c))
55+
#define ISWORDCHR(c) (t_isalnum(c))
5656
#define ISPRINTABLECHAR(a) ( isascii( *(unsigned char*)(a) ) && (isalnum( *(unsigned char*)(a) ) || *(unsigned char*)(a)==' ') )
5757
#else
5858
#define ISWORDCHR(c) (!t_isspace(c))

src/backend/tsearch/ts_locale.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,22 @@ t_isalpha(const char *ptr)
8181
return iswalpha((wint_t) character[0]);
8282
}
8383

84+
int
85+
t_isalnum(const char *ptr)
86+
{
87+
int clen = pg_mblen(ptr);
88+
wchar_t character[WC_BUF_LEN];
89+
Oid collation = DEFAULT_COLLATION_OID; /* TODO */
90+
pg_locale_t mylocale = 0; /* TODO */
91+
92+
if (clen == 1 || lc_ctype_is_c(collation))
93+
return isalnum(TOUCHAR(ptr));
94+
95+
char2wchar(character, WC_BUF_LEN, ptr, clen, mylocale);
96+
97+
return iswalnum((wint_t) character[0]);
98+
}
99+
84100
int
85101
t_isprint(const char *ptr)
86102
{

src/backend/utils/adt/tsquery.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ parse_or_operator(TSQueryParserState pstate)
248248
return false;
249249

250250
/* it shouldn't be a part of any word */
251-
if (t_iseq(ptr, '-') || t_iseq(ptr, '_') || t_isalpha(ptr) || t_isdigit(ptr))
251+
if (t_iseq(ptr, '-') || t_iseq(ptr, '_') || t_isalnum(ptr))
252252
return false;
253253

254254
for (;;)

src/include/tsearch/ts_locale.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ typedef struct
4242
extern int t_isdigit(const char *ptr);
4343
extern int t_isspace(const char *ptr);
4444
extern int t_isalpha(const char *ptr);
45+
extern int t_isalnum(const char *ptr);
4546
extern int t_isprint(const char *ptr);
4647

4748
extern char *lowerstr(const char *str);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy