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,40 +166,44 @@ Datum
|
|||||||
lower(PG_FUNCTION_ARGS)
|
lower(PG_FUNCTION_ARGS)
|
||||||
{
|
{
|
||||||
#ifdef USE_WIDE_UPPER_LOWER
|
#ifdef USE_WIDE_UPPER_LOWER
|
||||||
text *string = PG_GETARG_TEXT_P(0);
|
/* use wide char code only when max encoding length > one */
|
||||||
text *result;
|
if (pg_database_encoding_max_length() > 1)
|
||||||
wchar_t *workspace;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
workspace = texttowcs(string);
|
|
||||||
|
|
||||||
for (i = 0; workspace[i] != 0; i++)
|
|
||||||
workspace[i] = towlower(workspace[i]);
|
|
||||||
|
|
||||||
result = wcstotext(workspace, i);
|
|
||||||
|
|
||||||
pfree(workspace);
|
|
||||||
|
|
||||||
PG_RETURN_TEXT_P(result);
|
|
||||||
|
|
||||||
#else /* !USE_WIDE_UPPER_LOWER */
|
|
||||||
|
|
||||||
text *string = PG_GETARG_TEXT_P_COPY(0);
|
|
||||||
char *ptr;
|
|
||||||
int m;
|
|
||||||
|
|
||||||
/* Since we copied the string, we can scribble directly on the value */
|
|
||||||
ptr = VARDATA(string);
|
|
||||||
m = VARSIZE(string) - VARHDRSZ;
|
|
||||||
|
|
||||||
while (m-- > 0)
|
|
||||||
{
|
{
|
||||||
*ptr = tolower((unsigned char) *ptr);
|
text *string = PG_GETARG_TEXT_P(0);
|
||||||
ptr++;
|
text *result;
|
||||||
}
|
wchar_t *workspace;
|
||||||
|
int i;
|
||||||
|
|
||||||
PG_RETURN_TEXT_P(string);
|
workspace = texttowcs(string);
|
||||||
|
|
||||||
|
for (i = 0; workspace[i] != 0; i++)
|
||||||
|
workspace[i] = towlower(workspace[i]);
|
||||||
|
|
||||||
|
result = wcstotext(workspace, i);
|
||||||
|
|
||||||
|
pfree(workspace);
|
||||||
|
|
||||||
|
PG_RETURN_TEXT_P(result);
|
||||||
|
}
|
||||||
|
else
|
||||||
#endif /* USE_WIDE_UPPER_LOWER */
|
#endif /* USE_WIDE_UPPER_LOWER */
|
||||||
|
{
|
||||||
|
text *string = PG_GETARG_TEXT_P_COPY(0);
|
||||||
|
char *ptr;
|
||||||
|
int m;
|
||||||
|
|
||||||
|
/* Since we copied the string, we can scribble directly on the value */
|
||||||
|
ptr = VARDATA(string);
|
||||||
|
m = VARSIZE(string) - VARHDRSZ;
|
||||||
|
|
||||||
|
while (m-- > 0)
|
||||||
|
{
|
||||||
|
*ptr = tolower((unsigned char) *ptr);
|
||||||
|
ptr++;
|
||||||
|
}
|
||||||
|
|
||||||
|
PG_RETURN_TEXT_P(string);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -221,40 +225,44 @@ Datum
|
|||||||
upper(PG_FUNCTION_ARGS)
|
upper(PG_FUNCTION_ARGS)
|
||||||
{
|
{
|
||||||
#ifdef USE_WIDE_UPPER_LOWER
|
#ifdef USE_WIDE_UPPER_LOWER
|
||||||
text *string = PG_GETARG_TEXT_P(0);
|
/* use wide char code only when max encoding length > one */
|
||||||
text *result;
|
if (pg_database_encoding_max_length() > 1)
|
||||||
wchar_t *workspace;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
workspace = texttowcs(string);
|
|
||||||
|
|
||||||
for (i = 0; workspace[i] != 0; i++)
|
|
||||||
workspace[i] = towupper(workspace[i]);
|
|
||||||
|
|
||||||
result = wcstotext(workspace, i);
|
|
||||||
|
|
||||||
pfree(workspace);
|
|
||||||
|
|
||||||
PG_RETURN_TEXT_P(result);
|
|
||||||
|
|
||||||
#else /* !USE_WIDE_UPPER_LOWER */
|
|
||||||
|
|
||||||
text *string = PG_GETARG_TEXT_P_COPY(0);
|
|
||||||
char *ptr;
|
|
||||||
int m;
|
|
||||||
|
|
||||||
/* Since we copied the string, we can scribble directly on the value */
|
|
||||||
ptr = VARDATA(string);
|
|
||||||
m = VARSIZE(string) - VARHDRSZ;
|
|
||||||
|
|
||||||
while (m-- > 0)
|
|
||||||
{
|
{
|
||||||
*ptr = toupper((unsigned char) *ptr);
|
text *string = PG_GETARG_TEXT_P(0);
|
||||||
ptr++;
|
text *result;
|
||||||
}
|
wchar_t *workspace;
|
||||||
|
int i;
|
||||||
|
|
||||||
PG_RETURN_TEXT_P(string);
|
workspace = texttowcs(string);
|
||||||
|
|
||||||
|
for (i = 0; workspace[i] != 0; i++)
|
||||||
|
workspace[i] = towupper(workspace[i]);
|
||||||
|
|
||||||
|
result = wcstotext(workspace, i);
|
||||||
|
|
||||||
|
pfree(workspace);
|
||||||
|
|
||||||
|
PG_RETURN_TEXT_P(result);
|
||||||
|
}
|
||||||
|
else
|
||||||
#endif /* USE_WIDE_UPPER_LOWER */
|
#endif /* USE_WIDE_UPPER_LOWER */
|
||||||
|
{
|
||||||
|
text *string = PG_GETARG_TEXT_P_COPY(0);
|
||||||
|
char *ptr;
|
||||||
|
int m;
|
||||||
|
|
||||||
|
/* Since we copied the string, we can scribble directly on the value */
|
||||||
|
ptr = VARDATA(string);
|
||||||
|
m = VARSIZE(string) - VARHDRSZ;
|
||||||
|
|
||||||
|
while (m-- > 0)
|
||||||
|
{
|
||||||
|
*ptr = toupper((unsigned char) *ptr);
|
||||||
|
ptr++;
|
||||||
|
}
|
||||||
|
|
||||||
|
PG_RETURN_TEXT_P(string);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -279,58 +287,56 @@ Datum
|
|||||||
initcap(PG_FUNCTION_ARGS)
|
initcap(PG_FUNCTION_ARGS)
|
||||||
{
|
{
|
||||||
#ifdef USE_WIDE_UPPER_LOWER
|
#ifdef USE_WIDE_UPPER_LOWER
|
||||||
text *string = PG_GETARG_TEXT_P(0);
|
/* use wide char code only when max encoding length > one */
|
||||||
text *result;
|
if (pg_database_encoding_max_length() > 1)
|
||||||
wchar_t *workspace;
|
|
||||||
int wasalnum = 0;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
workspace = texttowcs(string);
|
|
||||||
|
|
||||||
for (i = 0; workspace[i] != 0; i++)
|
|
||||||
{
|
{
|
||||||
if (wasalnum)
|
text *string = PG_GETARG_TEXT_P(0);
|
||||||
workspace[i] = towlower(workspace[i]);
|
text *result;
|
||||||
else
|
wchar_t *workspace;
|
||||||
workspace[i] = towupper(workspace[i]);
|
int wasalnum = 0;
|
||||||
wasalnum = iswalnum(workspace[i]);
|
int i;
|
||||||
|
|
||||||
|
workspace = texttowcs(string);
|
||||||
|
|
||||||
|
for (i = 0; workspace[i] != 0; i++)
|
||||||
|
{
|
||||||
|
if (wasalnum)
|
||||||
|
workspace[i] = towlower(workspace[i]);
|
||||||
|
else
|
||||||
|
workspace[i] = towupper(workspace[i]);
|
||||||
|
wasalnum = iswalnum(workspace[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
result = wcstotext(workspace, i);
|
||||||
|
|
||||||
|
pfree(workspace);
|
||||||
|
|
||||||
|
PG_RETURN_TEXT_P(result);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
result = wcstotext(workspace, i);
|
|
||||||
|
|
||||||
pfree(workspace);
|
|
||||||
|
|
||||||
PG_RETURN_TEXT_P(result);
|
|
||||||
|
|
||||||
#else /* !USE_WIDE_UPPER_LOWER */
|
|
||||||
|
|
||||||
text *string = PG_GETARG_TEXT_P_COPY(0);
|
|
||||||
char *ptr;
|
|
||||||
int m;
|
|
||||||
|
|
||||||
/* Since we copied the string, we can scribble directly on the value */
|
|
||||||
ptr = VARDATA(string);
|
|
||||||
m = VARSIZE(string) - VARHDRSZ;
|
|
||||||
|
|
||||||
if (m > 0)
|
|
||||||
{
|
|
||||||
*ptr = toupper((unsigned char) *ptr);
|
|
||||||
ptr++;
|
|
||||||
m--;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (m-- > 0)
|
|
||||||
{
|
|
||||||
/* Oracle capitalizes after all non-alphanumeric */
|
|
||||||
if (!isalnum((unsigned char) ptr[-1]))
|
|
||||||
*ptr = toupper((unsigned char) *ptr);
|
|
||||||
else
|
|
||||||
*ptr = tolower((unsigned char) *ptr);
|
|
||||||
ptr++;
|
|
||||||
}
|
|
||||||
|
|
||||||
PG_RETURN_TEXT_P(string);
|
|
||||||
#endif /* USE_WIDE_UPPER_LOWER */
|
#endif /* USE_WIDE_UPPER_LOWER */
|
||||||
|
{
|
||||||
|
text *string = PG_GETARG_TEXT_P_COPY(0);
|
||||||
|
int wasalnum = 0;
|
||||||
|
char *ptr;
|
||||||
|
int m;
|
||||||
|
|
||||||
|
/* Since we copied the string, we can scribble directly on the value */
|
||||||
|
ptr = VARDATA(string);
|
||||||
|
m = VARSIZE(string) - VARHDRSZ;
|
||||||
|
|
||||||
|
while (m-- > 0)
|
||||||
|
{
|
||||||
|
if (wasalnum)
|
||||||
|
*ptr = tolower((unsigned char) *ptr);
|
||||||
|
else
|
||||||
|
*ptr = toupper((unsigned char) *ptr);
|
||||||
|
wasalnum = isalnum((unsigned char) *ptr);
|
||||||
|
ptr++;
|
||||||
|
}
|
||||||
|
|
||||||
|
PG_RETURN_TEXT_P(string);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user