aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/oracle_compat.c
diff options
context:
space:
mode:
authorBruce Momjian <bruce@momjian.us>2007-02-08 18:19:33 +0000
committerBruce Momjian <bruce@momjian.us>2007-02-08 18:19:33 +0000
commitb577aa9ebc780c5095f213d36253f63580b2a067 (patch)
treeec39e6caab7d1e4fa72803eb22d27e3642d6f927 /src/backend/utils/adt/oracle_compat.c
parenta37b006d89b85c4b8ca92ee53580a1c3ea385be7 (diff)
downloadpostgresql-b577aa9ebc780c5095f213d36253f63580b2a067.tar.gz
postgresql-b577aa9ebc780c5095f213d36253f63580b2a067.zip
Fix bug when localized to_char() day or month names were incorectly
trnasformed to lower or upper string. Pavel Stehule
Diffstat (limited to 'src/backend/utils/adt/oracle_compat.c')
-rw-r--r--src/backend/utils/adt/oracle_compat.c78
1 files changed, 77 insertions, 1 deletions
diff --git a/src/backend/utils/adt/oracle_compat.c b/src/backend/utils/adt/oracle_compat.c
index c6c4175dd6b..6da6b30cca3 100644
--- a/src/backend/utils/adt/oracle_compat.c
+++ b/src/backend/utils/adt/oracle_compat.c
@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/oracle_compat.c,v 1.68 2007/01/05 22:19:41 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/oracle_compat.c,v 1.69 2007/02/08 18:19:33 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 */
/********************************************************************
*