From 29800e82d24e70bd7e127ea1e6574dbbf89684a6 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Mon, 2 Dec 2024 11:34:17 +0100 Subject: [PATCH v2 1/4] Remove t_isdigit() --- contrib/ltree/ltree_io.c | 8 ++++---- src/backend/tsearch/spell.c | 4 ++-- src/backend/tsearch/ts_locale.c | 15 --------------- src/backend/utils/adt/tsquery.c | 2 +- src/backend/utils/adt/tsvector_parser.c | 4 ++-- src/include/tsearch/ts_locale.h | 1 - 6 files changed, 9 insertions(+), 25 deletions(-) diff --git a/contrib/ltree/ltree_io.c b/contrib/ltree/ltree_io.c index 11eefc809b2..b54a15d6c68 100644 --- a/contrib/ltree/ltree_io.c +++ b/contrib/ltree/ltree_io.c @@ -411,7 +411,7 @@ parse_lquery(const char *buf, struct Node *escontext) case LQPRS_WAITFNUM: if (t_iseq(ptr, ',')) state = LQPRS_WAITSNUM; - else if (t_isdigit(ptr)) + else if (isdigit((unsigned char) *ptr)) { int low = atoi(ptr); @@ -429,7 +429,7 @@ parse_lquery(const char *buf, struct Node *escontext) UNCHAR; break; case LQPRS_WAITSNUM: - if (t_isdigit(ptr)) + if (isdigit((unsigned char) *ptr)) { int high = atoi(ptr); @@ -460,7 +460,7 @@ parse_lquery(const char *buf, struct Node *escontext) case LQPRS_WAITCLOSE: if (t_iseq(ptr, '}')) state = LQPRS_WAITEND; - else if (!t_isdigit(ptr)) + else if (!isdigit((unsigned char) *ptr)) UNCHAR; break; case LQPRS_WAITND: @@ -471,7 +471,7 @@ parse_lquery(const char *buf, struct Node *escontext) } else if (t_iseq(ptr, ',')) state = LQPRS_WAITSNUM; - else if (!t_isdigit(ptr)) + else if (!isdigit((unsigned char) *ptr)) UNCHAR; break; case LQPRS_WAITEND: diff --git a/src/backend/tsearch/spell.c b/src/backend/tsearch/spell.c index aaedb0aa852..7800f794e84 100644 --- a/src/backend/tsearch/spell.c +++ b/src/backend/tsearch/spell.c @@ -390,7 +390,7 @@ getNextFlagFromString(IspellDict *Conf, const char **sflagset, char *sflag) *sflagset = next; while (**sflagset) { - if (t_isdigit(*sflagset)) + if (isdigit((unsigned char) **sflagset)) { if (!met_comma) ereport(ERROR, @@ -1750,7 +1750,7 @@ NISortDictionary(IspellDict *Conf) (errcode(ERRCODE_CONFIG_FILE_ERROR), errmsg("invalid affix alias \"%s\"", Conf->Spell[i]->p.flag))); - if (*end != '\0' && !t_isdigit(end) && !t_isspace(end)) + if (*end != '\0' && !isdigit((unsigned char) *end) && !t_isspace(end)) ereport(ERROR, (errcode(ERRCODE_CONFIG_FILE_ERROR), errmsg("invalid affix alias \"%s\"", diff --git a/src/backend/tsearch/ts_locale.c b/src/backend/tsearch/ts_locale.c index f8367b41312..7247b8cbe8a 100644 --- a/src/backend/tsearch/ts_locale.c +++ b/src/backend/tsearch/ts_locale.c @@ -31,21 +31,6 @@ static void tsearch_readline_callback(void *arg); */ #define WC_BUF_LEN 3 -int -t_isdigit(const char *ptr) -{ - int clen = pg_mblen(ptr); - wchar_t character[WC_BUF_LEN]; - pg_locale_t mylocale = 0; /* TODO */ - - if (clen == 1 || database_ctype_is_c) - return isdigit(TOUCHAR(ptr)); - - char2wchar(character, WC_BUF_LEN, ptr, clen, mylocale); - - return iswdigit((wint_t) character[0]); -} - int t_isspace(const char *ptr) { diff --git a/src/backend/utils/adt/tsquery.c b/src/backend/utils/adt/tsquery.c index 6f532188392..219ab543f62 100644 --- a/src/backend/utils/adt/tsquery.c +++ b/src/backend/utils/adt/tsquery.c @@ -197,7 +197,7 @@ parse_phrase_operator(TSQueryParserState pstate, int16 *distance) continue; } - if (!t_isdigit(ptr)) + if (!isdigit((unsigned char) *ptr)) return false; errno = 0; diff --git a/src/backend/utils/adt/tsvector_parser.c b/src/backend/utils/adt/tsvector_parser.c index ea961bb8a4a..9e33de0bde7 100644 --- a/src/backend/utils/adt/tsvector_parser.c +++ b/src/backend/utils/adt/tsvector_parser.c @@ -317,7 +317,7 @@ gettoken_tsvector(TSVectorParseState state, } else if (statecode == INPOSINFO) { - if (t_isdigit(state->prsbuf)) + if (isdigit((unsigned char) *state->prsbuf)) { if (posalen == 0) { @@ -375,7 +375,7 @@ gettoken_tsvector(TSVectorParseState state, else if (t_isspace(state->prsbuf) || *(state->prsbuf) == '\0') RETURN_TOKEN; - else if (!t_isdigit(state->prsbuf)) + else if (!isdigit((unsigned char) *state->prsbuf)) PRSSYNTAXERROR; } else /* internal error */ diff --git a/src/include/tsearch/ts_locale.h b/src/include/tsearch/ts_locale.h index abc21a7ebea..8ef380791fe 100644 --- a/src/include/tsearch/ts_locale.h +++ b/src/include/tsearch/ts_locale.h @@ -39,7 +39,6 @@ typedef struct #define COPYCHAR(d,s) memcpy(d, s, pg_mblen(s)) -extern int t_isdigit(const char *ptr); extern int t_isspace(const char *ptr); extern int t_isalpha(const char *ptr); extern int t_isalnum(const char *ptr); -- 2.47.1