mirror of
https://github.com/postgres/postgres.git
synced 2025-06-30 21:42:05 +03:00
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.
This commit is contained in:
@ -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
|
|||||||
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)
|
|||||||
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)
|
|||||||
}
|
}
|
||||||
|
|
||||||
PG_RETURN_TEXT_P(string);
|
PG_RETURN_TEXT_P(string);
|
||||||
#endif /* USE_WIDE_UPPER_LOWER */
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -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)
|
|||||||
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)
|
|||||||
}
|
}
|
||||||
|
|
||||||
PG_RETURN_TEXT_P(string);
|
PG_RETURN_TEXT_P(string);
|
||||||
#endif /* USE_WIDE_UPPER_LOWER */
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -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)
|
|||||||
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)
|
|||||||
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 */
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user