Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitca71131

Browse files
committed
Introduce t_isalnum() to replace t_isalpha() || t_isdigit() tests.
ts_locale.c omitted support for "isalnum" tests, perhaps on thegrounds that there were initially no use-cases for that. However,both ltree and pg_trgm need such tests, and we do also have oneuse-case now in the core backend. The workaround of testingisalpha and isdigit separately seems quite inefficient, especiallywhen dealing with multibyte characters; so let's fill in themissing support.Discussion:https://postgr.es/m/2548310.1664999615@sss.pgh.pa.us
1 parent5757141 commitca71131

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
#defineLQUERY_HASNOT0x01
128128

129-
#defineISALNUM(x)(t_isalpha(x)|| t_isdigit(x)|| ( pg_mblen(x) == 1 && t_iseq((x), '_') ) )
129+
#defineISALNUM(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
#ifdefKEEPONLYALNUM
55-
#defineISWORDCHR(c)(t_isalpha(c) || t_isdigit(c))
55+
#defineISWORDCHR(c)(t_isalnum(c))
5656
#defineISPRINTABLECHAR(a)( isascii( *(unsigned char*)(a) ) && (isalnum( *(unsigned char*)(a) ) || *(unsigned char*)(a)==' ') )
5757
#else
5858
#defineISWORDCHR(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
returniswalpha((wint_t)character[0]);
8282
}
8383

84+
int
85+
t_isalnum(constchar*ptr)
86+
{
87+
intclen=pg_mblen(ptr);
88+
wchar_tcharacter[WC_BUF_LEN];
89+
Oidcollation=DEFAULT_COLLATION_OID;/* TODO */
90+
pg_locale_tmylocale=0;/* TODO */
91+
92+
if (clen==1||lc_ctype_is_c(collation))
93+
returnisalnum(TOUCHAR(ptr));
94+
95+
char2wchar(character,WC_BUF_LEN,ptr,clen,mylocale);
96+
97+
returniswalnum((wint_t)character[0]);
98+
}
99+
84100
int
85101
t_isprint(constchar*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
externintt_isdigit(constchar*ptr);
4343
externintt_isspace(constchar*ptr);
4444
externintt_isalpha(constchar*ptr);
45+
externintt_isalnum(constchar*ptr);
4546
externintt_isprint(constchar*ptr);
4647

4748
externchar*lowerstr(constchar*str);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp