summaryrefslogtreecommitdiff
path: root/src/backend/tsearch/ts_locale.c
diff options
context:
space:
mode:
authorPeter Eisentraut2024-12-17 13:04:55 +0000
committerPeter Eisentraut2024-12-17 13:04:55 +0000
commitfb1a18810f07fc3b722392103d67ce8ed188b63d (patch)
treeea418d1a2e82d3104644f550c6a71366f3acfa6c /src/backend/tsearch/ts_locale.c
parentd3aad4ac57c5592ade77916404e6d8a989a1d6a1 (diff)
Remove ts_locale.c's lowerstr()
lowerstr() and lowerstr_with_len() in ts_locale.c do the same thing as str_tolower() that the rest of the system uses, except that the former don't use the common locale provider framework but instead use the global libc locale settings. This patch replaces uses of lowerstr*() with str_tolower(..., DEFAULT_COLLATION_OID). For instances that use a libc locale globally, this will result in exactly the same behavior. For instances that use other locale providers, you now get consistent behavior and are no longer dependent on the libc locale settings (for this case; there are others). Most uses of these functions are for processing dictionary and configuration files. In those cases, using the default collation seems appropriate. At least we don't have a more specific collation available. But the code in contrib/pg_trgm should really depend on the collation of the columns being processed. This is not done here, this can be done in a separate patch. (You can probably construct some edge cases where this change would create some locale-related upgrade incompatibility, for example if before you used a combination of ICU and a differently-behaving libc locale. We can document this in the release notes, but I don't think there is anything more we can do about this.) Reviewed-by: Jeff Davis <[email protected]> Discussion: https://www.postgresql.org/message-id/flat/653f3b84-fc87-45a7-9a0c-bfb4fcab3e7d%40eisentraut.org
Diffstat (limited to 'src/backend/tsearch/ts_locale.c')
-rw-r--r--src/backend/tsearch/ts_locale.c89
1 files changed, 0 insertions, 89 deletions
diff --git a/src/backend/tsearch/ts_locale.c b/src/backend/tsearch/ts_locale.c
index a61fd36022e..b2aefa31c26 100644
--- a/src/backend/tsearch/ts_locale.c
+++ b/src/backend/tsearch/ts_locale.c
@@ -197,92 +197,3 @@ tsearch_readline_callback(void *arg)
stp->lineno,
stp->filename);
}
-
-
-/*
- * lowerstr --- fold null-terminated string to lower case
- *
- * Returned string is palloc'd
- */
-char *
-lowerstr(const char *str)
-{
- return lowerstr_with_len(str, strlen(str));
-}
-
-/*
- * lowerstr_with_len --- fold string to lower case
- *
- * Input string need not be null-terminated.
- *
- * Returned string is palloc'd
- */
-char *
-lowerstr_with_len(const char *str, int len)
-{
- char *out;
- pg_locale_t mylocale = 0; /* TODO */
-
- if (len == 0)
- return pstrdup("");
-
- /*
- * Use wide char code only when max encoding length > 1 and ctype != C.
- * Some operating systems fail with multi-byte encodings and a C locale.
- * Also, for a C locale there is no need to process as multibyte. From
- * backend/utils/adt/oracle_compat.c Teodor
- */
- if (pg_database_encoding_max_length() > 1 && !database_ctype_is_c)
- {
- wchar_t *wstr,
- *wptr;
- int wlen;
-
- /*
- * alloc number of wchar_t for worst case, len contains number of
- * bytes >= number of characters and alloc 1 wchar_t for 0, because
- * wchar2char wants zero-terminated string
- */
- wptr = wstr = (wchar_t *) palloc(sizeof(wchar_t) * (len + 1));
-
- wlen = char2wchar(wstr, len + 1, str, len, mylocale);
- Assert(wlen <= len);
-
- while (*wptr)
- {
- *wptr = towlower((wint_t) *wptr);
- wptr++;
- }
-
- /*
- * Alloc result string for worst case + '\0'
- */
- len = pg_database_encoding_max_length() * wlen + 1;
- out = (char *) palloc(len);
-
- wlen = wchar2char(out, wstr, len, mylocale);
-
- pfree(wstr);
-
- if (wlen < 0)
- ereport(ERROR,
- (errcode(ERRCODE_CHARACTER_NOT_IN_REPERTOIRE),
- errmsg("conversion from wchar_t to server encoding failed: %m")));
- Assert(wlen < len);
- }
- else
- {
- const char *ptr = str;
- char *outptr;
-
- outptr = out = (char *) palloc(sizeof(char) * (len + 1));
- while ((ptr - str) < len && *ptr)
- {
- *outptr++ = tolower(TOUCHAR(ptr));
- ptr++;
- }
- *outptr = '\0';
- }
-
- return out;
-}