From 61a93ed2da5adbacc57cc3b4b00805a7e3c868df Mon Sep 17 00:00:00 2001
From: Tatsuo Ishii <ishii@postgresql.org>
Date: Wed, 24 Nov 1999 03:45:12 +0000
Subject: [PATCH] Add multi-byte support to lztextlen()

---
 src/backend/utils/adt/lztext.c | 29 +++++++++++++++++++++++++----
 1 file changed, 25 insertions(+), 4 deletions(-)

diff --git a/src/backend/utils/adt/lztext.c b/src/backend/utils/adt/lztext.c
index a07ddebcf19..6ff128515b6 100644
--- a/src/backend/utils/adt/lztext.c
+++ b/src/backend/utils/adt/lztext.c
@@ -1,7 +1,7 @@
 /* ----------
  * lztext.c -
  *
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/lztext.c,v 1.2 1999/11/17 22:18:45 wieck Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/lztext.c,v 1.3 1999/11/24 03:45:12 ishii Exp $
  *
  *	Text type with internal LZ compressed representation. Uses the
  *	standard PostgreSQL compression method.
@@ -21,7 +21,9 @@
 #include "utils/builtins.h"
 #include "utils/palloc.h"
 #include "utils/pg_lzcompress.h"
-
+#ifdef MULTIBYTE
+#include "mb/pg_wchar.h"
+#endif
 
 /* ----------
  * lztextin -
@@ -134,6 +136,12 @@ lztextout(lztext *lz)
 int32
 lztextlen(lztext *lz)
 {
+#ifdef MULTIBYTE
+	unsigned char	*s1,*s2;
+	int	len;
+	int	l;
+	int	wl;
+#endif
 	/* ----------
 	 * Handle NULL
 	 * ----------
@@ -141,11 +149,26 @@ lztextlen(lztext *lz)
 	if (lz == NULL)
 		return 0;
 
+#ifdef MULTIBYTE
+	len = 0;
+	s1 = s2 = (unsigned char *)lztextout(lz);
+	l = PGLZ_RAW_SIZE(lz);
+	while (l > 0)
+	{
+		wl = pg_mblen(s1);
+		l -= wl;
+		s1 += wl;
+		len++;
+	}
+	pfree((char *)s2);
+	return (len);
+#else
 	/* ----------
 	 * without multibyte support, it's the remembered rawsize
 	 * ----------
 	 */
 	return PGLZ_RAW_SIZE(lz);
+#endif
 }
 
 
@@ -228,8 +251,6 @@ text_lztext(text *txt)
 	}
 
 	return result;
-
-	
 }
 
 
-- 
GitLab