]> granicus.if.org Git - postgresql/commitdiff
Add multi-byte support to lztextlen()
authorTatsuo Ishii <ishii@postgresql.org>
Wed, 24 Nov 1999 03:45:12 +0000 (03:45 +0000)
committerTatsuo Ishii <ishii@postgresql.org>
Wed, 24 Nov 1999 03:45:12 +0000 (03:45 +0000)
src/backend/utils/adt/lztext.c

index a07ddebcf19876754a906b337f80e75b6fa423ff..6ff128515b614b7f0b506e5b72c1a956f86bfb06 100644 (file)
@@ -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;
-
-       
 }