1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-03 20:02:46 +03:00

Fix bug when localized to_char() day or month names were incorectly

trnasformed to lower or upper string.

Backpatch to 8.2.X.

Pavel Stehule
This commit is contained in:
Bruce Momjian
2007-02-08 20:33:54 +00:00
parent d1be38cc7d
commit d6c1e1682c
2 changed files with 206 additions and 17 deletions

View File

@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/oracle_compat.c,v 1.67 2006/07/14 16:59:19 tgl Exp $
* $PostgreSQL: pgsql/src/backend/utils/adt/oracle_compat.c,v 1.67.2.1 2007/02/08 20:33:54 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@ -46,6 +46,8 @@
*/
#if defined(HAVE_WCSTOMBS) && defined(HAVE_TOWLOWER)
#define USE_WIDE_UPPER_LOWER
char *wstring_lower (char *str);
char *wstring_upper(char *str);
#endif
static text *dotrim(const char *string, int stringlen,
@ -258,6 +260,80 @@ win32_wcstotext(const wchar_t *str, int ncodes)
#define wcstotext win32_wcstotext
#endif /* WIN32 */
#ifdef USE_WIDE_UPPER_LOWER
/*
* string_upper and string_lower are used for correct multibyte upper/lower
* transformations localized strings. Returns pointers to transformated
* string.
*/
char *
wstring_upper(char *str)
{
wchar_t *workspace;
text *in_text;
text *out_text;
char *result;
int nbytes = strlen(str);
int i;
in_text = palloc(nbytes + VARHDRSZ);
memcpy(VARDATA(in_text), str, nbytes);
VARATT_SIZEP(in_text) = nbytes + VARHDRSZ;
workspace = texttowcs(in_text);
for (i = 0; workspace[i] != 0; i++)
workspace[i] = towupper(workspace[i]);
out_text = wcstotext(workspace, i);
nbytes = VARSIZE(out_text) - VARHDRSZ;
result = palloc(nbytes + 1);
memcpy(result, VARDATA(out_text), nbytes);
result[nbytes] = '\0';
pfree(workspace);
pfree(in_text);
pfree(out_text);
return result;
}
char *
wstring_lower(char *str)
{
wchar_t *workspace;
text *in_text;
text *out_text;
char *result;
int nbytes = strlen(str);
int i;
in_text = palloc(nbytes + VARHDRSZ);
memcpy(VARDATA(in_text), str, nbytes);
VARATT_SIZEP(in_text) = nbytes + VARHDRSZ;
workspace = texttowcs(in_text);
for (i = 0; workspace[i] != 0; i++)
workspace[i] = towlower(workspace[i]);
out_text = wcstotext(workspace, i);
nbytes = VARSIZE(out_text) - VARHDRSZ;
result = palloc(nbytes + 1);
memcpy(result, VARDATA(out_text), nbytes);
result[nbytes] = '\0';
pfree(workspace);
pfree(in_text);
pfree(out_text);
return result;
}
#endif /* USE_WIDE_UPPER_LOWER */
/********************************************************************
*