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

Commitd3aad4a

Browse files
committed
Remove ts_locale.c's t_isdigit(), t_isspace(), t_isprint()
These do the same thing as the standard isdigit(), isspace(), andisprint() but with multibyte and encoding support. But all thecallers are only interested in analyzing single-byte ASCII characters.So this extra layer is overkill and we can replace the uses with thestandard functions.All the t_is*() functions in ts_locale.c are under scrutiny becausethey don't use the common locale provider framework but instead usethe global libc locale settings. For the functions being touched bythis patch, we don't need all that anyway, as mentioned above, so thesimplest solution is to just remove them. The few remaining t_is*()functions will need a different treatment in a separate patch.pg_trgm has some compile-time options with macros such asKEEPONLYALNUM. These are not documented, and the non-default variantis not supported by any test cases. As part of this undertaking, I'mremoving the non-default variant, as it is in the way of cleanup. Soin this case, the not-KEEPONLYALNUM code path is gone.Reviewed-by: Jeff Davis <pgsql@j-davis.com>Discussion:https://www.postgresql.org/message-id/flat/653f3b84-fc87-45a7-9a0c-bfb4fcab3e7d%40eisentraut.org
1 parent60be3f9 commitd3aad4a

File tree

13 files changed

+49
-103
lines changed

13 files changed

+49
-103
lines changed

‎contrib/dict_xsyn/dict_xsyn.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@ find_word(char *in, char **end)
4848
char*start;
4949

5050
*end=NULL;
51-
while (*in&&t_isspace(in))
51+
while (*in&&isspace((unsignedchar)*in))
5252
in+=pg_mblen(in);
5353

5454
if (!*in||*in=='#')
5555
returnNULL;
5656
start=in;
5757

58-
while (*in&& !t_isspace(in))
58+
while (*in&& !isspace((unsignedchar)*in))
5959
in+=pg_mblen(in);
6060

6161
*end=in;

‎contrib/ltree/ltree_io.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ parse_lquery(const char *buf, struct Node *escontext)
411411
caseLQPRS_WAITFNUM:
412412
if (t_iseq(ptr,','))
413413
state=LQPRS_WAITSNUM;
414-
elseif (t_isdigit(ptr))
414+
elseif (isdigit((unsignedchar)*ptr))
415415
{
416416
intlow=atoi(ptr);
417417

@@ -429,7 +429,7 @@ parse_lquery(const char *buf, struct Node *escontext)
429429
UNCHAR;
430430
break;
431431
caseLQPRS_WAITSNUM:
432-
if (t_isdigit(ptr))
432+
if (isdigit((unsignedchar)*ptr))
433433
{
434434
inthigh=atoi(ptr);
435435

@@ -460,7 +460,7 @@ parse_lquery(const char *buf, struct Node *escontext)
460460
caseLQPRS_WAITCLOSE:
461461
if (t_iseq(ptr,'}'))
462462
state=LQPRS_WAITEND;
463-
elseif (!t_isdigit(ptr))
463+
elseif (!isdigit((unsignedchar)*ptr))
464464
UNCHAR;
465465
break;
466466
caseLQPRS_WAITND:
@@ -471,7 +471,7 @@ parse_lquery(const char *buf, struct Node *escontext)
471471
}
472472
elseif (t_iseq(ptr,','))
473473
state=LQPRS_WAITSNUM;
474-
elseif (!t_isdigit(ptr))
474+
elseif (!isdigit((unsignedchar)*ptr))
475475
UNCHAR;
476476
break;
477477
caseLQPRS_WAITEND:

‎contrib/ltree/ltxtquery_io.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ gettoken_query(QPRS_STATE *state, int32 *val, int32 *lenval, char **strval, uint
8888
*lenval=charlen;
8989
*flag=0;
9090
}
91-
elseif (!t_isspace(state->buf))
91+
elseif (!isspace((unsignedchar)*state->buf))
9292
ereturn(state->escontext,ERR,
9393
(errcode(ERRCODE_SYNTAX_ERROR),
9494
errmsg("operand syntax error")));

‎contrib/pg_trgm/trgm.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
#defineLPADDING2
1717
#defineRPADDING1
18-
#defineKEEPONLYALNUM
1918
/*
2019
* Caution: IGNORECASE macro means that trigrams are case-insensitive.
2120
* If this macro is disabled, the ~* and ~~* operators must be removed from
@@ -51,13 +50,8 @@ typedef char trgm[3];
5150
*(((char*)(a))+2) = *(((char*)(b))+2);\
5251
} while(0)
5352

54-
#ifdefKEEPONLYALNUM
5553
#defineISWORDCHR(c)(t_isalnum(c))
5654
#defineISPRINTABLECHAR(a)( isascii( *(unsigned char*)(a) ) && (isalnum( *(unsigned char*)(a) ) || *(unsigned char*)(a)==' ') )
57-
#else
58-
#defineISWORDCHR(c)(!t_isspace(c))
59-
#defineISPRINTABLECHAR(a)( isascii( *(unsigned char*)(a) ) && isprint( *(unsigned char*)(a) ) )
60-
#endif
6155
#defineISPRINTABLETRGM(t)( ISPRINTABLECHAR( ((char*)(t)) ) && ISPRINTABLECHAR( ((char*)(t))+1 ) && ISPRINTABLECHAR( ((char*)(t))+2 ) )
6256

6357
#defineISESCAPECHAR(x) (*(x) == '\\')/* Wildcard escape character */

‎contrib/unaccent/unaccent.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ initTrie(const char *filename)
155155
{
156156
ptrlen=pg_mblen(ptr);
157157
/* ignore whitespace, but end src or trg */
158-
if (t_isspace(ptr))
158+
if (isspace((unsignedchar)*ptr))
159159
{
160160
if (state==1)
161161
state=2;

‎src/backend/tsearch/dict_synonym.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ findwrd(char *in, char **end, uint16 *flags)
4747
char*lastchar;
4848

4949
/* Skip leading spaces */
50-
while (*in&&t_isspace(in))
50+
while (*in&&isspace((unsignedchar)*in))
5151
in+=pg_mblen(in);
5252

5353
/* Return NULL on empty lines */
@@ -60,7 +60,7 @@ findwrd(char *in, char **end, uint16 *flags)
6060
lastchar=start=in;
6161

6262
/* Find end of word */
63-
while (*in&& !t_isspace(in))
63+
while (*in&& !isspace((unsignedchar)*in))
6464
{
6565
lastchar=in;
6666
in+=pg_mblen(in);

‎src/backend/tsearch/dict_thesaurus.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ thesaurusRead(const char *filename, DictThesaurus *d)
190190
ptr=line;
191191

192192
/* is it a comment? */
193-
while (*ptr&&t_isspace(ptr))
193+
while (*ptr&&isspace((unsignedchar)*ptr))
194194
ptr+=pg_mblen(ptr);
195195

196196
if (t_iseq(ptr,'#')||*ptr=='\0'||
@@ -212,7 +212,7 @@ thesaurusRead(const char *filename, DictThesaurus *d)
212212
errmsg("unexpected delimiter")));
213213
state=TR_WAITSUBS;
214214
}
215-
elseif (!t_isspace(ptr))
215+
elseif (!isspace((unsignedchar)*ptr))
216216
{
217217
beginwrd=ptr;
218218
state=TR_INLEX;
@@ -225,7 +225,7 @@ thesaurusRead(const char *filename, DictThesaurus *d)
225225
newLexeme(d,beginwrd,ptr,idsubst,posinsubst++);
226226
state=TR_WAITSUBS;
227227
}
228-
elseif (t_isspace(ptr))
228+
elseif (isspace((unsignedchar)*ptr))
229229
{
230230
newLexeme(d,beginwrd,ptr,idsubst,posinsubst++);
231231
state=TR_WAITLEX;
@@ -245,7 +245,7 @@ thesaurusRead(const char *filename, DictThesaurus *d)
245245
state=TR_INSUBS;
246246
beginwrd=ptr+pg_mblen(ptr);
247247
}
248-
elseif (!t_isspace(ptr))
248+
elseif (!isspace((unsignedchar)*ptr))
249249
{
250250
useasis= false;
251251
beginwrd=ptr;
@@ -254,7 +254,7 @@ thesaurusRead(const char *filename, DictThesaurus *d)
254254
}
255255
elseif (state==TR_INSUBS)
256256
{
257-
if (t_isspace(ptr))
257+
if (isspace((unsignedchar)*ptr))
258258
{
259259
if (ptr==beginwrd)
260260
ereport(ERROR,

‎src/backend/tsearch/spell.c

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ getNextFlagFromString(IspellDict *Conf, const char **sflagset, char *sflag)
390390
*sflagset=next;
391391
while (**sflagset)
392392
{
393-
if (t_isdigit(*sflagset))
393+
if (isdigit((unsignedchar)**sflagset))
394394
{
395395
if (!met_comma)
396396
ereport(ERROR,
@@ -408,7 +408,7 @@ getNextFlagFromString(IspellDict *Conf, const char **sflagset, char *sflag)
408408
*sflagset)));
409409
met_comma= true;
410410
}
411-
elseif (!t_isspace(*sflagset))
411+
elseif (!isspace((unsignedchar)**sflagset))
412412
{
413413
ereport(ERROR,
414414
(errcode(ERRCODE_CONFIG_FILE_ERROR),
@@ -542,7 +542,7 @@ NIImportDictionary(IspellDict *Conf, const char *filename)
542542
while (*s)
543543
{
544544
/* we allow only single encoded flags for faster works */
545-
if (pg_mblen(s)==1&&t_isprint(s)&& !t_isspace(s))
545+
if (pg_mblen(s)==1&&isprint((unsignedchar)*s)&& !isspace((unsignedchar)*s))
546546
s++;
547547
else
548548
{
@@ -558,7 +558,7 @@ NIImportDictionary(IspellDict *Conf, const char *filename)
558558
s=line;
559559
while (*s)
560560
{
561-
if (t_isspace(s))
561+
if (isspace((unsignedchar)*s))
562562
{
563563
*s='\0';
564564
break;
@@ -799,7 +799,7 @@ get_nextfield(char **str, char *next)
799799
{
800800
if (t_iseq(*str,'#'))
801801
return false;
802-
elseif (!t_isspace(*str))
802+
elseif (!isspace((unsignedchar)**str))
803803
{
804804
intclen=pg_mblen(*str);
805805

@@ -814,7 +814,7 @@ get_nextfield(char **str, char *next)
814814
}
815815
else/* state == PAE_INMASK */
816816
{
817-
if (t_isspace(*str))
817+
if (isspace((unsignedchar)**str))
818818
{
819819
*next='\0';
820820
return true;
@@ -925,7 +925,7 @@ parse_affentry(char *str, char *mask, char *find, char *repl)
925925
{
926926
if (t_iseq(str,'#'))
927927
return false;
928-
elseif (!t_isspace(str))
928+
elseif (!isspace((unsignedchar)*str))
929929
{
930930
COPYCHAR(pmask,str);
931931
pmask+=pg_mblen(str);
@@ -939,7 +939,7 @@ parse_affentry(char *str, char *mask, char *find, char *repl)
939939
*pmask='\0';
940940
state=PAE_WAIT_FIND;
941941
}
942-
elseif (!t_isspace(str))
942+
elseif (!isspace((unsignedchar)*str))
943943
{
944944
COPYCHAR(pmask,str);
945945
pmask+=pg_mblen(str);
@@ -957,7 +957,7 @@ parse_affentry(char *str, char *mask, char *find, char *repl)
957957
prepl+=pg_mblen(str);
958958
state=PAE_INREPL;
959959
}
960-
elseif (!t_isspace(str))
960+
elseif (!isspace((unsignedchar)*str))
961961
ereport(ERROR,
962962
(errcode(ERRCODE_CONFIG_FILE_ERROR),
963963
errmsg("syntax error")));
@@ -974,7 +974,7 @@ parse_affentry(char *str, char *mask, char *find, char *repl)
974974
COPYCHAR(pfind,str);
975975
pfind+=pg_mblen(str);
976976
}
977-
elseif (!t_isspace(str))
977+
elseif (!isspace((unsignedchar)*str))
978978
ereport(ERROR,
979979
(errcode(ERRCODE_CONFIG_FILE_ERROR),
980980
errmsg("syntax error")));
@@ -991,7 +991,7 @@ parse_affentry(char *str, char *mask, char *find, char *repl)
991991
prepl+=pg_mblen(str);
992992
state=PAE_INREPL;
993993
}
994-
elseif (!t_isspace(str))
994+
elseif (!isspace((unsignedchar)*str))
995995
ereport(ERROR,
996996
(errcode(ERRCODE_CONFIG_FILE_ERROR),
997997
errmsg("syntax error")));
@@ -1008,7 +1008,7 @@ parse_affentry(char *str, char *mask, char *find, char *repl)
10081008
COPYCHAR(prepl,str);
10091009
prepl+=pg_mblen(str);
10101010
}
1011-
elseif (!t_isspace(str))
1011+
elseif (!isspace((unsignedchar)*str))
10121012
ereport(ERROR,
10131013
(errcode(ERRCODE_CONFIG_FILE_ERROR),
10141014
errmsg("syntax error")));
@@ -1070,7 +1070,7 @@ addCompoundAffixFlagValue(IspellDict *Conf, char *s, uint32 val)
10701070
char*sflag;
10711071
intclen;
10721072

1073-
while (*s&&t_isspace(s))
1073+
while (*s&&isspace((unsignedchar)*s))
10741074
s+=pg_mblen(s);
10751075

10761076
if (!*s)
@@ -1080,7 +1080,7 @@ addCompoundAffixFlagValue(IspellDict *Conf, char *s, uint32 val)
10801080

10811081
/* Get flag without \n */
10821082
sflag=sbuf;
1083-
while (*s&& !t_isspace(s)&&*s!='\n')
1083+
while (*s&& !isspace((unsignedchar)*s)&&*s!='\n')
10841084
{
10851085
clen=pg_mblen(s);
10861086
COPYCHAR(sflag,s);
@@ -1225,7 +1225,7 @@ NIImportOOAffixes(IspellDict *Conf, const char *filename)
12251225

12261226
while ((recoded=tsearch_readline(&trst))!=NULL)
12271227
{
1228-
if (*recoded=='\0'||t_isspace(recoded)||t_iseq(recoded,'#'))
1228+
if (*recoded=='\0'||isspace((unsignedchar)*recoded)||t_iseq(recoded,'#'))
12291229
{
12301230
pfree(recoded);
12311231
continue;
@@ -1262,7 +1262,7 @@ NIImportOOAffixes(IspellDict *Conf, const char *filename)
12621262
{
12631263
char*s=recoded+strlen("FLAG");
12641264

1265-
while (*s&&t_isspace(s))
1265+
while (*s&&isspace((unsignedchar)*s))
12661266
s+=pg_mblen(s);
12671267

12681268
if (*s)
@@ -1298,7 +1298,7 @@ NIImportOOAffixes(IspellDict *Conf, const char *filename)
12981298
{
12991299
intfields_read;
13001300

1301-
if (*recoded=='\0'||t_isspace(recoded)||t_iseq(recoded,'#'))
1301+
if (*recoded=='\0'||isspace((unsignedchar)*recoded)||t_iseq(recoded,'#'))
13021302
gotonextline;
13031303

13041304
fields_read=parse_ooaffentry(recoded,type,sflag,find,repl,mask);
@@ -1461,9 +1461,9 @@ NIImportAffixes(IspellDict *Conf, const char *filename)
14611461
s=findchar2(recoded,'l','L');
14621462
if (s)
14631463
{
1464-
while (*s&& !t_isspace(s))
1464+
while (*s&& !isspace((unsignedchar)*s))
14651465
s+=pg_mblen(s);
1466-
while (*s&&t_isspace(s))
1466+
while (*s&&isspace((unsignedchar)*s))
14671467
s+=pg_mblen(s);
14681468

14691469
if (*s&&pg_mblen(s)==1)
@@ -1494,7 +1494,7 @@ NIImportAffixes(IspellDict *Conf, const char *filename)
14941494
s=recoded+4;/* we need non-lowercased string */
14951495
flagflags=0;
14961496

1497-
while (*s&&t_isspace(s))
1497+
while (*s&&isspace((unsignedchar)*s))
14981498
s+=pg_mblen(s);
14991499

15001500
if (*s=='*')
@@ -1523,7 +1523,7 @@ NIImportAffixes(IspellDict *Conf, const char *filename)
15231523

15241524
s++;
15251525
if (*s=='\0'||*s=='#'||*s=='\n'||*s==':'||
1526-
t_isspace(s))
1526+
isspace((unsignedchar)*s))
15271527
{
15281528
oldformat= true;
15291529
gotonextline;
@@ -1750,7 +1750,7 @@ NISortDictionary(IspellDict *Conf)
17501750
(errcode(ERRCODE_CONFIG_FILE_ERROR),
17511751
errmsg("invalid affix alias \"%s\"",
17521752
Conf->Spell[i]->p.flag)));
1753-
if (*end!='\0'&& !t_isdigit(end)&& !t_isspace(end))
1753+
if (*end!='\0'&& !isdigit((unsignedchar)*end)&& !isspace((unsignedchar)*end))
17541754
ereport(ERROR,
17551755
(errcode(ERRCODE_CONFIG_FILE_ERROR),
17561756
errmsg("invalid affix alias \"%s\"",

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp