aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/utils')
-rw-r--r--src/backend/utils/adt/ascii.c44
-rw-r--r--src/backend/utils/adt/format_type.c9
-rw-r--r--src/backend/utils/adt/like.c44
-rw-r--r--src/backend/utils/adt/oracle_compat.c166
-rw-r--r--src/backend/utils/adt/quote.c100
-rw-r--r--src/backend/utils/adt/selfuncs.c6
-rw-r--r--src/backend/utils/adt/varchar.c80
-rw-r--r--src/backend/utils/adt/varlena.c10
-rw-r--r--src/backend/utils/error/elog.c8
-rw-r--r--src/backend/utils/init/postinit.c9
-rw-r--r--src/backend/utils/mb/mbutils.c33
11 files changed, 53 insertions, 456 deletions
diff --git a/src/backend/utils/adt/ascii.c b/src/backend/utils/adt/ascii.c
index a62672a5e53..0a2820721dc 100644
--- a/src/backend/utils/adt/ascii.c
+++ b/src/backend/utils/adt/ascii.c
@@ -1,7 +1,7 @@
/* -----------------------------------------------------------------------
* ascii.c
*
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/ascii.c,v 1.12 2001/11/05 17:46:28 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/ascii.c,v 1.13 2002/08/29 07:22:26 ishii Exp $
*
* Portions Copyright (c) 1999-2000, PostgreSQL Global Development Group
*
@@ -18,46 +18,6 @@
#include "mb/pg_wchar.h"
#include "utils/ascii.h"
-/* ----------
- * even if MULTIBYTE is not enabled, these functions must exist
- * since pg_proc.h has references to them.
- * ----------
- */
-#ifndef MULTIBYTE
-
-static void multibyte_error(void);
-
-static void
-multibyte_error(void)
-{
- elog(ERROR, "Multi-byte support is not enabled");
-}
-
-Datum
-to_ascii_encname(PG_FUNCTION_ARGS)
-{
- multibyte_error();
- return 0; /* keep compiler quiet */
-}
-
-Datum
-to_ascii_enc(PG_FUNCTION_ARGS)
-{
- multibyte_error();
- return 0; /* keep compiler quiet */
-}
-
-Datum
-to_ascii_default(PG_FUNCTION_ARGS)
-{
- multibyte_error();
- return 0; /* keep compiler quiet */
-}
-
-
-#else /* with MULTIBYTE */
-
-
static text *encode_to_ascii(text *data, int enc);
/* ----------
@@ -190,5 +150,3 @@ to_ascii_default(PG_FUNCTION_ARGS)
)
);
}
-
-#endif /* MULTIBYTE */
diff --git a/src/backend/utils/adt/format_type.c b/src/backend/utils/adt/format_type.c
index 2aca3d7fc5f..02e0dc8f27d 100644
--- a/src/backend/utils/adt/format_type.c
+++ b/src/backend/utils/adt/format_type.c
@@ -8,7 +8,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/format_type.c,v 1.32 2002/08/24 15:00:46 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/format_type.c,v 1.33 2002/08/29 07:22:26 ishii Exp $
*
*-------------------------------------------------------------------------
*/
@@ -25,9 +25,7 @@
#include "utils/numeric.h"
#include "utils/lsyscache.h"
#include "utils/syscache.h"
-#ifdef MULTIBYTE
#include "mb/pg_wchar.h"
-#endif
#define MAX_INT32_LEN 11
#define _textin(str) DirectFunctionCall1(textin, CStringGetDatum(str))
@@ -433,14 +431,11 @@ type_maximum_size(Oid type_oid, int32 typemod)
case BPCHAROID:
case VARCHAROID:
/* typemod includes varlena header */
-#ifdef MULTIBYTE
+
/* typemod is in characters not bytes */
return (typemod - VARHDRSZ) *
pg_encoding_max_length(GetDatabaseEncoding())
+ VARHDRSZ;
-#else
- return typemod;
-#endif
case NUMERICOID:
/* precision (ie, max # of digits) is in upper bits of typmod */
diff --git a/src/backend/utils/adt/like.c b/src/backend/utils/adt/like.c
index 1ce4de6d99a..3e67e947a9d 100644
--- a/src/backend/utils/adt/like.c
+++ b/src/backend/utils/adt/like.c
@@ -11,7 +11,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/like.c,v 1.50 2002/08/22 04:45:11 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/like.c,v 1.51 2002/08/29 07:22:26 ishii Exp $
*
*-------------------------------------------------------------------------
*/
@@ -19,9 +19,7 @@
#include <ctype.h>
-#ifdef MULTIBYTE
#include "mb/pg_wchar.h"
-#endif
#include "utils/builtins.h"
@@ -38,7 +36,6 @@ static int MatchBytea(unsigned char *t, int tlen,
unsigned char *p, int plen);
static text *do_like_escape(text *, text *);
-#ifdef MULTIBYTE
static int MBMatchText(unsigned char *t, int tlen,
unsigned char *p, int plen);
static int MBMatchTextIC(unsigned char *t, int tlen,
@@ -107,9 +104,7 @@ iwchareq(unsigned char *p1, unsigned char *p2)
c2[0] = tolower(c2[0]);
return (c1[0] == c2[0]);
}
-#endif
-#ifdef MULTIBYTE
#define CHAREQ(p1, p2) wchareq(p1, p2)
#define ICHAREQ(p1, p2) iwchareq(p1, p2)
#define NextChar(p, plen) \
@@ -132,7 +127,6 @@ iwchareq(unsigned char *p1, unsigned char *p2)
#undef MatchText
#undef MatchTextIC
#undef do_like_escape
-#endif
#define CHAREQ(p1, p2) (*(p1) == *(p2))
#define ICHAREQ(p1, p2) (tolower(*(p1)) == tolower(*(p2)))
@@ -164,14 +158,10 @@ namelike(PG_FUNCTION_ARGS)
p = VARDATA(pat);
plen = (VARSIZE(pat) - VARHDRSZ);
-#ifdef MULTIBYTE
if (pg_database_encoding_max_length() == 1)
result = (MatchText(s, slen, p, plen) == LIKE_TRUE);
else
result = (MBMatchText(s, slen, p, plen) == LIKE_TRUE);
-#else
- result = (MatchText(s, slen, p, plen) == LIKE_TRUE);
-#endif
PG_RETURN_BOOL(result);
}
@@ -192,14 +182,10 @@ namenlike(PG_FUNCTION_ARGS)
p = VARDATA(pat);
plen = (VARSIZE(pat) - VARHDRSZ);
-#ifdef MULTIBYTE
if (pg_database_encoding_max_length() == 1)
result = (MatchText(s, slen, p, plen) != LIKE_TRUE);
else
result = (MBMatchText(s, slen, p, plen) != LIKE_TRUE);
-#else
- result = (MatchText(s, slen, p, plen) != LIKE_TRUE);
-#endif
PG_RETURN_BOOL(result);
}
@@ -220,14 +206,10 @@ textlike(PG_FUNCTION_ARGS)
p = VARDATA(pat);
plen = (VARSIZE(pat) - VARHDRSZ);
-#ifdef MULTIBYTE
if (pg_database_encoding_max_length() == 1)
result = (MatchText(s, slen, p, plen) == LIKE_TRUE);
else
result = (MBMatchText(s, slen, p, plen) == LIKE_TRUE);
-#else
- result = (MatchText(s, slen, p, plen) == LIKE_TRUE);
-#endif
PG_RETURN_BOOL(result);
}
@@ -248,14 +230,10 @@ textnlike(PG_FUNCTION_ARGS)
p = VARDATA(pat);
plen = (VARSIZE(pat) - VARHDRSZ);
-#ifdef MULTIBYTE
if (pg_database_encoding_max_length() == 1)
result = (MatchText(s, slen, p, plen) != LIKE_TRUE);
else
result = (MBMatchText(s, slen, p, plen) != LIKE_TRUE);
-#else
- result = (MatchText(s, slen, p, plen) != LIKE_TRUE);
-#endif
PG_RETURN_BOOL(result);
}
@@ -322,14 +300,10 @@ nameiclike(PG_FUNCTION_ARGS)
p = VARDATA(pat);
plen = (VARSIZE(pat) - VARHDRSZ);
-#ifdef MULTIBYTE
if (pg_database_encoding_max_length() == 1)
result = (MatchTextIC(s, slen, p, plen) == LIKE_TRUE);
else
result = (MBMatchTextIC(s, slen, p, plen) == LIKE_TRUE);
-#else
- result = (MatchTextIC(s, slen, p, plen) == LIKE_TRUE);
-#endif
PG_RETURN_BOOL(result);
}
@@ -350,14 +324,10 @@ nameicnlike(PG_FUNCTION_ARGS)
p = VARDATA(pat);
plen = (VARSIZE(pat) - VARHDRSZ);
-#ifdef MULTIBYTE
if (pg_database_encoding_max_length() == 1)
result = (MatchTextIC(s, slen, p, plen) != LIKE_TRUE);
else
result = (MBMatchTextIC(s, slen, p, plen) != LIKE_TRUE);
-#else
- result = (MatchTextIC(s, slen, p, plen) != LIKE_TRUE);
-#endif
PG_RETURN_BOOL(result);
}
@@ -378,14 +348,10 @@ texticlike(PG_FUNCTION_ARGS)
p = VARDATA(pat);
plen = (VARSIZE(pat) - VARHDRSZ);
-#ifdef MULTIBYTE
if (pg_database_encoding_max_length() == 1)
result = (MatchTextIC(s, slen, p, plen) == LIKE_TRUE);
else
result = (MBMatchTextIC(s, slen, p, plen) == LIKE_TRUE);
-#else
- result = (MatchTextIC(s, slen, p, plen) == LIKE_TRUE);
-#endif
PG_RETURN_BOOL(result);
}
@@ -406,14 +372,10 @@ texticnlike(PG_FUNCTION_ARGS)
p = VARDATA(pat);
plen = (VARSIZE(pat) - VARHDRSZ);
-#ifdef MULTIBYTE
if (pg_database_encoding_max_length() == 1)
result = (MatchTextIC(s, slen, p, plen) != LIKE_TRUE);
else
result = (MBMatchTextIC(s, slen, p, plen) != LIKE_TRUE);
-#else
- result = (MatchTextIC(s, slen, p, plen) != LIKE_TRUE);
-#endif
PG_RETURN_BOOL(result);
}
@@ -429,14 +391,10 @@ like_escape(PG_FUNCTION_ARGS)
text *esc = PG_GETARG_TEXT_P(1);
text *result;
-#ifdef MULTIBYTE
if (pg_database_encoding_max_length() == 1)
result = do_like_escape(pat, esc);
else
result = MB_do_like_escape(pat, esc);
-#else
- result = do_like_escape(pat, esc);
-#endif
PG_RETURN_TEXT_P(result);
}
diff --git a/src/backend/utils/adt/oracle_compat.c b/src/backend/utils/adt/oracle_compat.c
index bd2d884b3fd..e71604719f7 100644
--- a/src/backend/utils/adt/oracle_compat.c
+++ b/src/backend/utils/adt/oracle_compat.c
@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/oracle_compat.c,v 1.41 2002/08/22 05:05:19 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/oracle_compat.c,v 1.42 2002/08/29 07:22:27 ishii Exp $
*
*-------------------------------------------------------------------------
*/
@@ -20,9 +20,7 @@
#include "utils/builtins.h"
-#ifdef MULTIBYTE
#include "mb/pg_wchar.h"
-#endif
/********************************************************************
*
@@ -172,9 +170,7 @@ lpad(PG_FUNCTION_ARGS)
s1len,
s2len;
-#ifdef MULTIBYTE
int bytelen;
-#endif
/* Negative len is silently taken as zero */
if (len < 0)
@@ -188,16 +184,14 @@ lpad(PG_FUNCTION_ARGS)
if (s2len < 0)
s2len = 0; /* shouldn't happen */
-#ifdef MULTIBYTE
s1len = pg_mbstrlen_with_len(VARDATA(string1), s1len);
-#endif
+
if (s1len > len)
s1len = len; /* truncate string1 to len chars */
if (s2len <= 0)
len = s1len; /* nothing to pad with, so don't pad */
-#ifdef MULTIBYTE
bytelen = pg_database_encoding_max_length() * len;
/* check for integer overflow */
@@ -205,16 +199,13 @@ lpad(PG_FUNCTION_ARGS)
elog(ERROR, "Requested length too large");
ret = (text *) palloc(VARHDRSZ + bytelen);
-#else
- ret = (text *) palloc(VARHDRSZ + len);
-#endif
+
m = len - s1len;
ptr2 = VARDATA(string2);
ptr2end = ptr2 + s2len;
ptr_ret = VARDATA(ret);
-#ifdef MULTIBYTE
while (m--)
{
int mlen = pg_mblen(ptr2);
@@ -225,18 +216,9 @@ lpad(PG_FUNCTION_ARGS)
if (ptr2 == ptr2end) /* wrap around at end of s2 */
ptr2 = VARDATA(string2);
}
-#else
- while (m--)
- {
- *ptr_ret++ = *ptr2++;
- if (ptr2 == ptr2end) /* wrap around at end of s2 */
- ptr2 = VARDATA(string2);
- }
-#endif
ptr1 = VARDATA(string1);
-#ifdef MULTIBYTE
while (s1len--)
{
int mlen = pg_mblen(ptr1);
@@ -245,10 +227,6 @@ lpad(PG_FUNCTION_ARGS)
ptr_ret += mlen;
ptr1 += mlen;
}
-#else
- while (s1len--)
- *ptr_ret++ = *ptr1++;
-#endif
VARATT_SIZEP(ret) = ptr_ret - (char *) ret;
@@ -287,9 +265,7 @@ rpad(PG_FUNCTION_ARGS)
s1len,
s2len;
-#ifdef MULTIBYTE
int bytelen;
-#endif
/* Negative len is silently taken as zero */
if (len < 0)
@@ -303,9 +279,7 @@ rpad(PG_FUNCTION_ARGS)
if (s2len < 0)
s2len = 0; /* shouldn't happen */
-#ifdef MULTIBYTE
s1len = pg_mbstrlen_with_len(VARDATA(string1), s1len);
-#endif
if (s1len > len)
s1len = len; /* truncate string1 to len chars */
@@ -313,7 +287,6 @@ rpad(PG_FUNCTION_ARGS)
if (s2len <= 0)
len = s1len; /* nothing to pad with, so don't pad */
-#ifdef MULTIBYTE
bytelen = pg_database_encoding_max_length() * len;
/* Check for integer overflow */
@@ -321,15 +294,11 @@ rpad(PG_FUNCTION_ARGS)
elog(ERROR, "Requested length too large");
ret = (text *) palloc(VARHDRSZ + bytelen);
-#else
- ret = (text *) palloc(VARHDRSZ + len);
-#endif
m = len - s1len;
ptr1 = VARDATA(string1);
ptr_ret = VARDATA(ret);
-#ifdef MULTIBYTE
while (s1len--)
{
int mlen = pg_mblen(ptr1);
@@ -338,15 +307,10 @@ rpad(PG_FUNCTION_ARGS)
ptr_ret += mlen;
ptr1 += mlen;
}
-#else
- while (s1len--)
- *ptr_ret++ = *ptr1++;
-#endif
ptr2 = VARDATA(string2);
ptr2end = ptr2 + s2len;
-#ifdef MULTIBYTE
while (m--)
{
int mlen = pg_mblen(ptr2);
@@ -357,14 +321,6 @@ rpad(PG_FUNCTION_ARGS)
if (ptr2 == ptr2end) /* wrap around at end of s2 */
ptr2 = VARDATA(string2);
}
-#else
- while (m--)
- {
- *ptr_ret++ = *ptr2++;
- if (ptr2 == ptr2end) /* wrap around at end of s2 */
- ptr2 = VARDATA(string2);
- }
-#endif
VARATT_SIZEP(ret) = ptr_ret - (char *) ret;
@@ -399,13 +355,11 @@ btrim(PG_FUNCTION_ARGS)
*end2;
int m;
-#ifdef MULTIBYTE
char **mp;
int mplen;
char *p;
int mblen;
int len;
-#endif
if ((m = VARSIZE(string) - VARHDRSZ) <= 0 ||
(VARSIZE(set) - VARHDRSZ) <= 0)
@@ -413,7 +367,6 @@ btrim(PG_FUNCTION_ARGS)
ptr = VARDATA(string);
-#ifdef MULTIBYTE
len = m;
mp = (char **) palloc(len * sizeof(char *));
p = ptr;
@@ -428,12 +381,8 @@ btrim(PG_FUNCTION_ARGS)
len -= mblen;
}
mplen--;
-#else
- end = VARDATA(string) + VARSIZE(string) - VARHDRSZ - 1;
-#endif
end2 = VARDATA(set) + VARSIZE(set) - VARHDRSZ - 1;
-#ifdef MULTIBYTE
while (m > 0)
{
int str_len = pg_mblen(ptr);
@@ -475,37 +424,6 @@ btrim(PG_FUNCTION_ARGS)
m -= str_len;
}
pfree(mp);
-#else
- while (m > 0)
- {
- ptr2 = VARDATA(set);
- while (ptr2 <= end2)
- {
- if (*ptr == *ptr2)
- break;
- ++ptr2;
- }
- if (ptr2 > end2)
- break;
- ptr++;
- m--;
- }
-
- while (m > 0)
- {
- ptr2 = VARDATA(set);
- while (ptr2 <= end2)
- {
- if (*end == *ptr2)
- break;
- ++ptr2;
- }
- if (ptr2 > end2)
- break;
- end--;
- m--;
- }
-#endif
ret = (text *) palloc(VARHDRSZ + m);
VARATT_SIZEP(ret) = VARHDRSZ + m;
memcpy(VARDATA(ret), ptr, m);
@@ -619,7 +537,6 @@ ltrim(PG_FUNCTION_ARGS)
ptr = VARDATA(string);
end2 = VARDATA(set) + VARSIZE(set) - VARHDRSZ - 1;
-#ifdef MULTIBYTE
while (m > 0)
{
int str_len = pg_mblen(ptr);
@@ -639,22 +556,6 @@ ltrim(PG_FUNCTION_ARGS)
ptr += str_len;
m -= str_len;
}
-#else
- while (m > 0)
- {
- ptr2 = VARDATA(set);
- while (ptr2 <= end2)
- {
- if (*ptr == *ptr2)
- break;
- ++ptr2;
- }
- if (ptr2 > end2)
- break;
- ptr++;
- m--;
- }
-#endif
ret = (text *) palloc(VARHDRSZ + m);
VARATT_SIZEP(ret) = VARHDRSZ + m;
memcpy(VARDATA(ret), ptr, m);
@@ -691,13 +592,11 @@ rtrim(PG_FUNCTION_ARGS)
*end2;
int m;
-#ifdef MULTIBYTE
char **mp;
int mplen;
char *p;
int mblen;
int len;
-#endif
if ((m = VARSIZE(string) - VARHDRSZ) <= 0 ||
(VARSIZE(set) - VARHDRSZ) <= 0)
@@ -705,7 +604,6 @@ rtrim(PG_FUNCTION_ARGS)
ptr = VARDATA(string);
-#ifdef MULTIBYTE
len = m;
mp = (char **) palloc(len * sizeof(char *));
p = ptr;
@@ -720,12 +618,8 @@ rtrim(PG_FUNCTION_ARGS)
len -= mblen;
}
mplen--;
-#else
- end = VARDATA(string) + VARSIZE(string) - VARHDRSZ - 1;
-#endif
end2 = VARDATA(set) + VARSIZE(set) - VARHDRSZ - 1;
-#ifdef MULTIBYTE
while (m > 0)
{
int str_len;
@@ -747,22 +641,6 @@ rtrim(PG_FUNCTION_ARGS)
m -= str_len;
}
pfree(mp);
-#else
- while (m > 0)
- {
- ptr2 = VARDATA(set);
- while (ptr2 <= end2)
- {
- if (*end == *ptr2)
- break;
- ++ptr2;
- }
- if (ptr2 > end2)
- break;
- end--;
- m--;
- }
-#endif
ret = (text *) palloc(VARHDRSZ + m);
VARATT_SIZEP(ret) = VARHDRSZ + m;
memcpy(VARDATA(ret), ptr, m);
@@ -805,13 +683,11 @@ translate(PG_FUNCTION_ARGS)
retlen,
i;
-#ifdef MULTIBYTE
int str_len;
int estimate_len;
int len;
int source_len;
int from_index;
-#endif
if ((m = VARSIZE(string) - VARHDRSZ) <= 0)
PG_RETURN_TEXT_P(string);
@@ -821,20 +697,15 @@ translate(PG_FUNCTION_ARGS)
tolen = VARSIZE(to) - VARHDRSZ;
to_ptr = VARDATA(to);
-#ifdef MULTIBYTE
str_len = VARSIZE(string);
estimate_len = (tolen * 1.0 / fromlen + 0.5) * str_len;
estimate_len = estimate_len > str_len ? estimate_len : str_len;
result = (text *) palloc(estimate_len);
-#else
- result = (text *) palloc(VARSIZE(string));
-#endif
source = VARDATA(string);
target = VARDATA(result);
retlen = 0;
-#ifdef MULTIBYTE
while (m > 0)
{
source_len = pg_mblen(source);
@@ -880,37 +751,6 @@ translate(PG_FUNCTION_ARGS)
source += source_len;
m -= source_len;
}
-#else
- while (m-- > 0)
- {
- char rep = *source++;
-
- for (i = 0; i < fromlen; i++)
- {
- if (from_ptr[i] == rep)
- break;
- }
- if (i < fromlen)
- {
- if (i < tolen)
- {
- /* substitute */
- *target++ = to_ptr[i];
- retlen++;
- }
- else
- {
- /* discard */
- }
- }
- else
- {
- /* no match, so copy */
- *target++ = rep;
- retlen++;
- }
- }
-#endif
VARATT_SIZEP(result) = retlen + VARHDRSZ;
diff --git a/src/backend/utils/adt/quote.c b/src/backend/utils/adt/quote.c
index 537e97a50ee..97946866d01 100644
--- a/src/backend/utils/adt/quote.c
+++ b/src/backend/utils/adt/quote.c
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/quote.c,v 1.7 2002/04/04 04:25:49 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/quote.c,v 1.8 2002/08/29 07:22:27 ishii Exp $
*
*-------------------------------------------------------------------------
*/
@@ -70,102 +70,6 @@ quote_literal(PG_FUNCTION_ARGS)
*
*/
-
-#ifndef MULTIBYTE
-
-/* Check if a given identifier needs quoting */
-static bool
-quote_ident_required(text *iptr)
-{
- char *cp;
- char *ep;
-
- cp = VARDATA(iptr);
- ep = VARDATA(iptr) + VARSIZE(iptr) - VARHDRSZ;
-
- if (cp >= ep)
- return true;
-
- if (!(*cp == '_' || (*cp >= 'a' && *cp <= 'z')))
- return true;
-
- while ((++cp) < ep)
- {
- if (*cp >= 'a' && *cp <= 'z')
- continue;
- if (*cp >= '0' && *cp <= '9')
- continue;
- if (*cp == '_')
- continue;
-
- return true;
- }
-
- return false;
-}
-
-/* Return a properly quoted identifier */
-static text *
-do_quote_ident(text *iptr)
-{
- text *result;
- char *cp1;
- char *cp2;
- int len;
-
- len = VARSIZE(iptr) - VARHDRSZ;
- result = (text *) palloc(len * 2 + VARHDRSZ + 2);
-
- cp1 = VARDATA(iptr);
- cp2 = VARDATA(result);
-
- *cp2++ = '"';
- while (len-- > 0)
- {
- if (*cp1 == '"')
- *cp2++ = '"';
- *cp2++ = *cp1++;
- }
- *cp2++ = '"';
-
- VARATT_SIZEP(result) = cp2 - ((char *) result);
-
- return result;
-}
-
-/* Return a properly quoted literal value */
-static text *
-do_quote_literal(text *lptr)
-{
- text *result;
- char *cp1;
- char *cp2;
- int len;
-
- len = VARSIZE(lptr) - VARHDRSZ;
- result = (text *) palloc(len * 2 + VARHDRSZ + 2);
-
- cp1 = VARDATA(lptr);
- cp2 = VARDATA(result);
-
- *cp2++ = '\'';
- while (len-- > 0)
- {
- if (*cp1 == '\'')
- *cp2++ = '\'';
- if (*cp1 == '\\')
- *cp2++ = '\\';
- *cp2++ = *cp1++;
- }
- *cp2++ = '\'';
-
- VARATT_SIZEP(result) = cp2 - ((char *) result);
-
- return result;
-}
-
-#else
-
/* Check if a given identifier needs quoting (MULTIBYTE version) */
static bool
quote_ident_required(text *iptr)
@@ -285,5 +189,3 @@ do_quote_literal(text *lptr)
return result;
}
-
-#endif
diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c
index 986c7659f2c..4835b0c3a5e 100644
--- a/src/backend/utils/adt/selfuncs.c
+++ b/src/backend/utils/adt/selfuncs.c
@@ -15,7 +15,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.113 2002/08/22 00:01:44 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.114 2002/08/29 07:22:27 ishii Exp $
*
*-------------------------------------------------------------------------
*/
@@ -3250,12 +3250,8 @@ make_greater_string(const char *str, Oid datatype)
* Truncate off the last character, which might be more than 1
* byte in MULTIBYTE case.
*/
-#ifdef MULTIBYTE
len = pg_mbcliplen((const unsigned char *) workstr, len, len - 1);
workstr[len] = '\0';
-#else
- *lastchar = '\0';
-#endif
}
/* Failed... */
diff --git a/src/backend/utils/adt/varchar.c b/src/backend/utils/adt/varchar.c
index cdf5c301d2e..e1181dd375f 100644
--- a/src/backend/utils/adt/varchar.c
+++ b/src/backend/utils/adt/varchar.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/varchar.c,v 1.91 2002/08/26 17:53:59 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/varchar.c,v 1.92 2002/08/29 07:22:27 ishii Exp $
*
*-------------------------------------------------------------------------
*/
@@ -21,9 +21,7 @@
#include "utils/builtins.h"
#include "utils/fmgroids.h"
-#ifdef MULTIBYTE
#include "mb/pg_wchar.h"
-#endif
/*
@@ -76,37 +74,26 @@ bpcharin(PG_FUNCTION_ARGS)
maxlen;
int i;
-#ifdef MULTIBYTE
int charlen; /* number of charcters in the input string */
char *ermsg;
-#endif
len = strlen(s);
-#ifdef MULTIBYTE
+
if ((ermsg = pg_verifymbstr(s, len)))
elog(ERROR, "%s", ermsg);
charlen = pg_mbstrlen(s);
-#endif
+
/* If typmod is -1 (or invalid), use the actual string length */
if (atttypmod < (int32) VARHDRSZ)
-#ifdef MULTIBYTE
maxlen = charlen;
-#else
- maxlen = len;
-#endif
else
maxlen = atttypmod - VARHDRSZ;
-#ifdef MULTIBYTE
if (charlen > maxlen)
-#else
- if (len > maxlen)
-#endif
{
/* Verify that extra characters are spaces, and clip them off */
-#ifdef MULTIBYTE
size_t mbmaxlen = pg_mbcharcliplen(s, len, maxlen);
/*
@@ -125,15 +112,7 @@ bpcharin(PG_FUNCTION_ARGS)
* the number of CHARACTERS!
*/
maxlen = len;
-#else
- if (strspn(s + maxlen, " ") == len - maxlen)
- len = maxlen;
- else
- elog(ERROR, "value too long for type character(%d)",
- (int) maxlen);
-#endif
}
-#ifdef MULTIBYTE
else
{
/*
@@ -142,7 +121,6 @@ bpcharin(PG_FUNCTION_ARGS)
*/
maxlen = len + (maxlen - charlen);
}
-#endif
result = palloc(maxlen + VARHDRSZ);
VARATT_SIZEP(result) = maxlen + VARHDRSZ;
@@ -202,26 +180,19 @@ bpchar(PG_FUNCTION_ARGS)
char *s;
int i;
-#ifdef MULTIBYTE
int charlen; /* number of charcters in the input string
* + VARHDRSZ */
-#endif
-
len = VARSIZE(source);
-#ifdef MULTIBYTE
+
charlen = pg_mbstrlen_with_len(VARDATA(source), len - VARHDRSZ) + VARHDRSZ;
-#endif
+
/* No work if typmod is invalid or supplied data matches it already */
if (maxlen < (int32) VARHDRSZ || len == maxlen)
PG_RETURN_BPCHAR_P(source);
-#ifdef MULTIBYTE
+
if (charlen > maxlen)
-#else
- if (len > maxlen)
-#endif
{
/* Verify that extra characters are spaces, and clip them off */
-#ifdef MULTIBYTE
size_t maxmblen;
maxmblen = pg_mbcharcliplen(VARDATA(source), len - VARHDRSZ,
@@ -239,16 +210,7 @@ bpchar(PG_FUNCTION_ARGS)
* length+VARHDRSZ, not the number of CHARACTERS!
*/
maxlen = len;
-#else
- for (i = maxlen - VARHDRSZ; i < len - VARHDRSZ; i++)
- if (*(VARDATA(source) + i) != ' ')
- elog(ERROR, "value too long for type character(%d)",
- maxlen - VARHDRSZ);
-
- len = maxlen;
-#endif
}
-#ifdef MULTIBYTE
else
{
/*
@@ -257,7 +219,6 @@ bpchar(PG_FUNCTION_ARGS)
*/
maxlen = len + (maxlen - charlen);
}
-#endif
s = VARDATA(source);
@@ -408,29 +369,22 @@ varcharin(PG_FUNCTION_ARGS)
size_t len,
maxlen;
-#ifdef MULTIBYTE
char *ermsg;
-#endif
len = strlen(s);
-#ifdef MULTIBYTE
+
if ((ermsg = pg_verifymbstr(s, len)))
elog(ERROR, "%s", ermsg);
-#endif
+
maxlen = atttypmod - VARHDRSZ;
if (atttypmod >= (int32) VARHDRSZ && len > maxlen)
{
/* Verify that extra characters are spaces, and clip them off */
-#ifdef MULTIBYTE
size_t mbmaxlen = pg_mbcharcliplen(s, len, maxlen);
if (strspn(s + mbmaxlen, " ") == len - mbmaxlen)
len = mbmaxlen;
-#else
- if (strspn(s + maxlen, " ") == len - maxlen)
- len = maxlen;
-#endif
else
elog(ERROR, "value too long for type character varying(%d)",
(int) maxlen);
@@ -493,7 +447,6 @@ varchar(PG_FUNCTION_ARGS)
/* only reach here if string is too long... */
-#ifdef MULTIBYTE
{
size_t maxmblen;
@@ -508,15 +461,6 @@ varchar(PG_FUNCTION_ARGS)
len = maxmblen;
}
-#else
- for (i = maxlen - VARHDRSZ; i < len - VARHDRSZ; i++)
- if (*(VARDATA(source) + i) != ' ')
- elog(ERROR, "value too long for type character varying(%d)",
- maxlen - VARHDRSZ);
-
- /* clip extra spaces */
- len = maxlen;
-#endif
result = palloc(len);
VARATT_SIZEP(result) = len;
@@ -584,7 +528,6 @@ bpcharlen(PG_FUNCTION_ARGS)
{
BpChar *arg = PG_GETARG_BPCHAR_P(0);
-#ifdef MULTIBYTE
/* optimization for single byte encoding */
if (pg_database_encoding_max_length() <= 1)
PG_RETURN_INT32(VARSIZE(arg) - VARHDRSZ);
@@ -592,9 +535,6 @@ bpcharlen(PG_FUNCTION_ARGS)
PG_RETURN_INT32(
pg_mbstrlen_with_len(VARDATA(arg), VARSIZE(arg) - VARHDRSZ)
);
-#else
- PG_RETURN_INT32(VARSIZE(arg) - VARHDRSZ);
-#endif
}
Datum
@@ -796,7 +736,6 @@ varcharlen(PG_FUNCTION_ARGS)
{
VarChar *arg = PG_GETARG_VARCHAR_P(0);
-#ifdef MULTIBYTE
/* optimization for single byte encoding */
if (pg_database_encoding_max_length() <= 1)
PG_RETURN_INT32(VARSIZE(arg) - VARHDRSZ);
@@ -804,9 +743,6 @@ varcharlen(PG_FUNCTION_ARGS)
PG_RETURN_INT32(
pg_mbstrlen_with_len(VARDATA(arg), VARSIZE(arg) - VARHDRSZ)
);
-#else
- PG_RETURN_INT32(VARSIZE(arg) - VARHDRSZ);
-#endif
}
Datum
diff --git a/src/backend/utils/adt/varlena.c b/src/backend/utils/adt/varlena.c
index 52598aba9e8..6e00a3e2835 100644
--- a/src/backend/utils/adt/varlena.c
+++ b/src/backend/utils/adt/varlena.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/varlena.c,v 1.89 2002/08/28 20:46:24 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/varlena.c,v 1.90 2002/08/29 07:22:27 ishii Exp $
*
*-------------------------------------------------------------------------
*/
@@ -217,16 +217,12 @@ textin(PG_FUNCTION_ARGS)
text *result;
int len;
-#ifdef MULTIBYTE
char *ermsg;
-#endif
len = strlen(inputText) + VARHDRSZ;
-#ifdef MULTIBYTE
if ((ermsg = pg_verifymbstr(inputText, len - VARHDRSZ)))
elog(ERROR, "%s", ermsg);
-#endif
result = (text *) palloc(len);
VARATT_SIZEP(result) = len;
@@ -1476,12 +1472,8 @@ SplitIdentifierString(char *rawstring, char separator,
curlen = strlen(curname);
if (curlen >= NAMEDATALEN)
{
-#ifdef MULTIBYTE
curlen = pg_mbcliplen(curname, curlen, NAMEDATALEN - 1);
curname[curlen] = '\0';
-#else
- curname[NAMEDATALEN - 1] = '\0';
-#endif
}
/*
diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c
index d26e55368db..fdd4388e5ca 100644
--- a/src/backend/utils/error/elog.c
+++ b/src/backend/utils/error/elog.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/error/elog.c,v 1.99 2002/06/20 20:29:39 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/error/elog.c,v 1.100 2002/08/29 07:22:28 ishii Exp $
*
*-------------------------------------------------------------------------
*/
@@ -35,9 +35,7 @@
#include "tcop/tcopprot.h"
#include "utils/memutils.h"
-#ifdef MULTIBYTE
#include "mb/pg_wchar.h"
-#endif
int server_min_messages;
char *server_min_messages_str = NULL;
@@ -694,14 +692,14 @@ write_syslog(int level, const char *line)
*strchr(buf, '\n') = '\0';
l = strlen(buf);
-#ifdef MULTIBYTE
+
/* trim to multibyte letter boundary */
buflen = pg_mbcliplen(buf, l, l);
if (buflen <= 0)
return;
buf[buflen] = '\0';
l = strlen(buf);
-#endif
+
/* already word boundary? */
if (isspace((unsigned char) line[l]) || line[l] == '\0')
buflen = l;
diff --git a/src/backend/utils/init/postinit.c b/src/backend/utils/init/postinit.c
index 433b9a5ed05..f36c1d981fa 100644
--- a/src/backend/utils/init/postinit.c
+++ b/src/backend/utils/init/postinit.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/init/postinit.c,v 1.109 2002/07/20 05:16:59 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/init/postinit.c,v 1.110 2002/08/29 07:22:28 ishii Exp $
*
*
*-------------------------------------------------------------------------
@@ -130,17 +130,10 @@ ReverifyMyDatabase(const char *name)
* encoding info out of the pg_database tuple --- or complain, if we
* can't support it.
*/
-#ifdef MULTIBYTE
SetDatabaseEncoding(dbform->encoding);
/* If we have no other source of client_encoding, use server encoding */
SetConfigOption("client_encoding", GetDatabaseEncodingName(),
PGC_BACKEND, PGC_S_DEFAULT);
-#else
- if (dbform->encoding != PG_SQL_ASCII)
- elog(FATAL, "database was initialized with MULTIBYTE encoding %d,\n\tbut the backend was compiled without multibyte support.\n\tlooks like you need to initdb or recompile.",
- dbform->encoding);
-#endif
-
/*
* Set up database-specific configuration variables.
*/
diff --git a/src/backend/utils/mb/mbutils.c b/src/backend/utils/mb/mbutils.c
index 4b77dcfa6a1..ef96f7d04b4 100644
--- a/src/backend/utils/mb/mbutils.c
+++ b/src/backend/utils/mb/mbutils.c
@@ -3,7 +3,7 @@
* client encoding and server internal encoding.
* (currently mule internal code (mic) is used)
* Tatsuo Ishii
- * $Id: mbutils.c,v 1.32 2002/08/19 04:08:08 ishii Exp $
+ * $Id: mbutils.c,v 1.33 2002/08/29 07:22:28 ishii Exp $
*/
#include "postgres.h"
#include "access/xact.h"
@@ -34,6 +34,9 @@ static FmgrInfo *ToClientConvPorc = NULL;
static unsigned char *
perform_default_encoding_conversion(unsigned char *src, int len, bool is_client_to_server);
+static int
+cliplen(const unsigned char *str, int len, int limit);
+
/*
* Set the client encoding and save fmgrinfo for the converion
* function if necessary. if encoding conversion between client/server
@@ -371,6 +374,10 @@ pg_mbstrlen(const unsigned char *mbstr)
{
int len = 0;
+ /* optimization for single byte encoding */
+ if (pg_database_encoding_max_length() == 1)
+ return strlen((char *)mbstr);
+
while (*mbstr)
{
mbstr += pg_mblen(mbstr);
@@ -409,6 +416,10 @@ pg_mbcliplen(const unsigned char *mbstr, int len, int limit)
int clen = 0;
int l;
+ /* optimization for single byte encoding */
+ if (pg_database_encoding_max_length() == 1)
+ return cliplen(mbstr, len, limit);
+
while (len > 0 && *mbstr)
{
l = pg_mblen(mbstr);
@@ -424,7 +435,7 @@ pg_mbcliplen(const unsigned char *mbstr, int len, int limit)
}
/*
- * Similar to pg_mbcliplen but the limit parameter specifies the
+ * Similar to pg_mbcliplen except the limit parameter specifies the
* character length, not the byte length. */
int
pg_mbcharcliplen(const unsigned char *mbstr, int len, int limit)
@@ -433,6 +444,10 @@ pg_mbcharcliplen(const unsigned char *mbstr, int len, int limit)
int nch = 0;
int l;
+ /* optimization for single byte encoding */
+ if (pg_database_encoding_max_length() == 1)
+ return cliplen(mbstr, len, limit);
+
while (len > 0 && *mbstr)
{
l = pg_mblen(mbstr);
@@ -489,3 +504,17 @@ pg_client_encoding(PG_FUNCTION_ARGS)
Assert(ClientEncoding);
return DirectFunctionCall1(namein, CStringGetDatum(ClientEncoding->name));
}
+
+static int
+cliplen(const unsigned char *str, int len, int limit)
+{
+ int l = 0;
+ const unsigned char *s;
+
+ for (s = str; *s; s++, l++)
+ {
+ if (l >= len || l >= limit)
+ return l;
+ }
+ return (s - str);
+}