Commit 7845bfc0 authored by Tom Lane's avatar Tom Lane

Dept of second thoughts: don't use the new wide-character upper/lower

code if we are running in a single-byte encoding.  No point in the
extra overhead in that case.
parent b8312c5f
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/oracle_compat.c,v 1.52 2004/05/26 16:16:03 tgl Exp $ * $PostgreSQL: pgsql/src/backend/utils/adt/oracle_compat.c,v 1.53 2004/06/06 22:17:01 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -166,6 +166,9 @@ Datum ...@@ -166,6 +166,9 @@ Datum
lower(PG_FUNCTION_ARGS) lower(PG_FUNCTION_ARGS)
{ {
#ifdef USE_WIDE_UPPER_LOWER #ifdef USE_WIDE_UPPER_LOWER
/* use wide char code only when max encoding length > one */
if (pg_database_encoding_max_length() > 1)
{
text *string = PG_GETARG_TEXT_P(0); text *string = PG_GETARG_TEXT_P(0);
text *result; text *result;
wchar_t *workspace; wchar_t *workspace;
...@@ -181,9 +184,10 @@ lower(PG_FUNCTION_ARGS) ...@@ -181,9 +184,10 @@ lower(PG_FUNCTION_ARGS)
pfree(workspace); pfree(workspace);
PG_RETURN_TEXT_P(result); PG_RETURN_TEXT_P(result);
}
#else /* !USE_WIDE_UPPER_LOWER */ else
#endif /* USE_WIDE_UPPER_LOWER */
{
text *string = PG_GETARG_TEXT_P_COPY(0); text *string = PG_GETARG_TEXT_P_COPY(0);
char *ptr; char *ptr;
int m; int m;
...@@ -199,7 +203,7 @@ lower(PG_FUNCTION_ARGS) ...@@ -199,7 +203,7 @@ lower(PG_FUNCTION_ARGS)
} }
PG_RETURN_TEXT_P(string); PG_RETURN_TEXT_P(string);
#endif /* USE_WIDE_UPPER_LOWER */ }
} }
...@@ -221,6 +225,9 @@ Datum ...@@ -221,6 +225,9 @@ Datum
upper(PG_FUNCTION_ARGS) upper(PG_FUNCTION_ARGS)
{ {
#ifdef USE_WIDE_UPPER_LOWER #ifdef USE_WIDE_UPPER_LOWER
/* use wide char code only when max encoding length > one */
if (pg_database_encoding_max_length() > 1)
{
text *string = PG_GETARG_TEXT_P(0); text *string = PG_GETARG_TEXT_P(0);
text *result; text *result;
wchar_t *workspace; wchar_t *workspace;
...@@ -236,9 +243,10 @@ upper(PG_FUNCTION_ARGS) ...@@ -236,9 +243,10 @@ upper(PG_FUNCTION_ARGS)
pfree(workspace); pfree(workspace);
PG_RETURN_TEXT_P(result); PG_RETURN_TEXT_P(result);
}
#else /* !USE_WIDE_UPPER_LOWER */ else
#endif /* USE_WIDE_UPPER_LOWER */
{
text *string = PG_GETARG_TEXT_P_COPY(0); text *string = PG_GETARG_TEXT_P_COPY(0);
char *ptr; char *ptr;
int m; int m;
...@@ -254,7 +262,7 @@ upper(PG_FUNCTION_ARGS) ...@@ -254,7 +262,7 @@ upper(PG_FUNCTION_ARGS)
} }
PG_RETURN_TEXT_P(string); PG_RETURN_TEXT_P(string);
#endif /* USE_WIDE_UPPER_LOWER */ }
} }
...@@ -279,6 +287,9 @@ Datum ...@@ -279,6 +287,9 @@ Datum
initcap(PG_FUNCTION_ARGS) initcap(PG_FUNCTION_ARGS)
{ {
#ifdef USE_WIDE_UPPER_LOWER #ifdef USE_WIDE_UPPER_LOWER
/* use wide char code only when max encoding length > one */
if (pg_database_encoding_max_length() > 1)
{
text *string = PG_GETARG_TEXT_P(0); text *string = PG_GETARG_TEXT_P(0);
text *result; text *result;
wchar_t *workspace; wchar_t *workspace;
...@@ -301,10 +312,12 @@ initcap(PG_FUNCTION_ARGS) ...@@ -301,10 +312,12 @@ initcap(PG_FUNCTION_ARGS)
pfree(workspace); pfree(workspace);
PG_RETURN_TEXT_P(result); PG_RETURN_TEXT_P(result);
}
#else /* !USE_WIDE_UPPER_LOWER */ else
#endif /* USE_WIDE_UPPER_LOWER */
{
text *string = PG_GETARG_TEXT_P_COPY(0); text *string = PG_GETARG_TEXT_P_COPY(0);
int wasalnum = 0;
char *ptr; char *ptr;
int m; int m;
...@@ -312,25 +325,18 @@ initcap(PG_FUNCTION_ARGS) ...@@ -312,25 +325,18 @@ initcap(PG_FUNCTION_ARGS)
ptr = VARDATA(string); ptr = VARDATA(string);
m = VARSIZE(string) - VARHDRSZ; m = VARSIZE(string) - VARHDRSZ;
if (m > 0)
{
*ptr = toupper((unsigned char) *ptr);
ptr++;
m--;
}
while (m-- > 0) while (m-- > 0)
{ {
/* Oracle capitalizes after all non-alphanumeric */ if (wasalnum)
if (!isalnum((unsigned char) ptr[-1]))
*ptr = toupper((unsigned char) *ptr);
else
*ptr = tolower((unsigned char) *ptr); *ptr = tolower((unsigned char) *ptr);
else
*ptr = toupper((unsigned char) *ptr);
wasalnum = isalnum((unsigned char) *ptr);
ptr++; ptr++;
} }
PG_RETURN_TEXT_P(string); PG_RETURN_TEXT_P(string);
#endif /* USE_WIDE_UPPER_LOWER */ }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment