mirror of
				https://github.com/postgres/postgres.git
				synced 2025-10-28 11:55:03 +03:00 
			
		
		
		
	Add multi-byte support to lztextlen()
This commit is contained in:
		| @@ -1,7 +1,7 @@ | |||||||
| /* ---------- | /* ---------- | ||||||
|  * lztext.c - |  * 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 |  *	Text type with internal LZ compressed representation. Uses the | ||||||
|  *	standard PostgreSQL compression method. |  *	standard PostgreSQL compression method. | ||||||
| @@ -21,7 +21,9 @@ | |||||||
| #include "utils/builtins.h" | #include "utils/builtins.h" | ||||||
| #include "utils/palloc.h" | #include "utils/palloc.h" | ||||||
| #include "utils/pg_lzcompress.h" | #include "utils/pg_lzcompress.h" | ||||||
|  | #ifdef MULTIBYTE | ||||||
|  | #include "mb/pg_wchar.h" | ||||||
|  | #endif | ||||||
|  |  | ||||||
| /* ---------- | /* ---------- | ||||||
|  * lztextin - |  * lztextin - | ||||||
| @@ -134,6 +136,12 @@ lztextout(lztext *lz) | |||||||
| int32 | int32 | ||||||
| lztextlen(lztext *lz) | lztextlen(lztext *lz) | ||||||
| { | { | ||||||
|  | #ifdef MULTIBYTE | ||||||
|  | 	unsigned char	*s1,*s2; | ||||||
|  | 	int	len; | ||||||
|  | 	int	l; | ||||||
|  | 	int	wl; | ||||||
|  | #endif | ||||||
| 	/* ---------- | 	/* ---------- | ||||||
| 	 * Handle NULL | 	 * Handle NULL | ||||||
| 	 * ---------- | 	 * ---------- | ||||||
| @@ -141,11 +149,26 @@ lztextlen(lztext *lz) | |||||||
| 	if (lz == NULL) | 	if (lz == NULL) | ||||||
| 		return 0; | 		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 | 	 * without multibyte support, it's the remembered rawsize | ||||||
| 	 * ---------- | 	 * ---------- | ||||||
| 	 */ | 	 */ | ||||||
| 	return PGLZ_RAW_SIZE(lz); | 	return PGLZ_RAW_SIZE(lz); | ||||||
|  | #endif | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
| @@ -228,8 +251,6 @@ text_lztext(text *txt) | |||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	return result; | 	return result; | ||||||
|  |  | ||||||
| 	 |  | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user