From f554af0a9fdbe0e9636fce36d6c809e81ce1539c Mon Sep 17 00:00:00 2001 From: "Marc G. Fournier" Date: Mon, 27 Apr 1998 17:10:50 +0000 Subject: From: t-ishii@sra.co.jp Hi, here are patches I promised (against 6.3.2): * character_length(), position(), substring() are now aware of multi-byte characters * add octet_length() * add --with-mb option to configure * new regression tests for EUC_KR (contributed by "Soonmyung. Hong" ) * add some test cases to the EUC_JP regression test * fix problem in regress/regress.sh in case of System V * fix toupper(), tolower() to handle 8bit chars note that: o patches for both configure.in and configure are included. maybe the one for configure is not necessary. o pg_proc.h was modified to add octet_length(). I used OIDs (1374-1379) for that. Please let me know if these numbers are not appropriate. --- src/backend/utils/adt/varchar.c | 54 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) (limited to 'src/backend/utils/adt/varchar.c') diff --git a/src/backend/utils/adt/varchar.c b/src/backend/utils/adt/varchar.c index 796cc3099a..cbd113bba8 100644 --- a/src/backend/utils/adt/varchar.c +++ b/src/backend/utils/adt/varchar.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/varchar.c,v 1.29 1998/02/26 04:37:24 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/varchar.c,v 1.30 1998/04/27 17:08:26 scrappy Exp $ * *------------------------------------------------------------------------- */ @@ -21,6 +21,8 @@ char *convertstr(char *, int, int); #endif +#include "regex/pg_wchar.h" + /* * CHAR() and VARCHAR() types are part of the ANSI SQL standard. CHAR() * is for blank-padded string whose length is specified in CREATE TABLE. @@ -213,6 +215,31 @@ bcTruelen(char *arg) int32 bpcharlen(char *arg) +{ +#ifdef MB + unsigned char *s; + int len, l, wl; +#endif + if (!PointerIsValid(arg)) + elog(ERROR, "Bad (null) char() external representation", NULL); +#ifdef MB + l = bcTruelen(arg); + len = 0; + s = VARDATA(arg); + while (l > 0) { + wl = pg_mblen(s); + l -= wl; + s += wl; + len++; + } + return(len); +#else + return (bcTruelen(arg)); +#endif +} + +int32 +bpcharoctetlen(char *arg) { if (!PointerIsValid(arg)) elog(ERROR, "Bad (null) char() external representation", NULL); @@ -354,9 +381,34 @@ bpcharcmp(char *arg1, char *arg2) int32 varcharlen(char *arg) { +#ifdef MB + unsigned char *s; + int len, l, wl; +#endif if (!PointerIsValid(arg)) elog(ERROR, "Bad (null) varchar() external representation", NULL); +#ifdef MB + len = 0; + s = VARDATA(arg); + l = VARSIZE(arg) - VARHDRSZ; + while (l > 0) { + wl = pg_mblen(s); + l -= wl; + s += wl; + len++; + } + return(len); +#else + return (VARSIZE(arg) - VARHDRSZ); +#endif +} + +int32 +varcharoctetlen(char *arg) +{ + if (!PointerIsValid(arg)) + elog(ERROR, "Bad (null) varchar() external representation", NULL); return (VARSIZE(arg) - VARHDRSZ); } -- cgit v1.2.1