mirror of
https://github.com/postgres/postgres.git
synced 2025-06-23 14:01:44 +03:00
MB patches from Tatsuo Ishii
This commit is contained in:
@ -7,7 +7,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/varchar.c,v 1.39 1998/09/01 04:32:53 momjian Exp $
|
* $Header: /cvsroot/pgsql/src/backend/utils/adt/varchar.c,v 1.40 1998/09/25 01:46:21 momjian Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -147,7 +147,14 @@ bpchar(char *s, int32 len)
|
|||||||
if ((len == -1) || (len == VARSIZE(s)))
|
if ((len == -1) || (len == VARSIZE(s)))
|
||||||
return s;
|
return s;
|
||||||
|
|
||||||
|
#ifdef MULTIBYTE
|
||||||
|
/* truncate multi-byte string in a way not to break
|
||||||
|
multi-byte boundary */
|
||||||
|
rlen = pg_mbcliplen(VARDATA(s), len - VARHDRSZ, len - VARHDRSZ);
|
||||||
|
len = rlen + VARHDRSZ;
|
||||||
|
#else
|
||||||
rlen = len - VARHDRSZ;
|
rlen = len - VARHDRSZ;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (rlen > 4096)
|
if (rlen > 4096)
|
||||||
elog(ERROR, "bpchar: length of char() must be less than 4096");
|
elog(ERROR, "bpchar: length of char() must be less than 4096");
|
||||||
@ -367,7 +374,14 @@ varchar(char *s, int32 slen)
|
|||||||
|
|
||||||
/* only reach here if we need to truncate string... */
|
/* only reach here if we need to truncate string... */
|
||||||
|
|
||||||
|
#ifdef MULTIBYTE
|
||||||
|
/* truncate multi-byte string in a way not to break
|
||||||
|
multi-byte boundary */
|
||||||
|
len = pg_mbcliplen(VARDATA(s), slen - VARHDRSZ, slen - VARHDRSZ);
|
||||||
|
slen = len + VARHDRSZ;
|
||||||
|
#else
|
||||||
len = slen - VARHDRSZ;
|
len = slen - VARHDRSZ;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (len > 4096)
|
if (len > 4096)
|
||||||
elog(ERROR, "varchar: length of varchar() must be less than 4096");
|
elog(ERROR, "varchar: length of varchar() must be less than 4096");
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
* client encoding and server internal encoding.
|
* client encoding and server internal encoding.
|
||||||
* (currently mule internal code (mic) is used)
|
* (currently mule internal code (mic) is used)
|
||||||
* Tatsuo Ishii
|
* Tatsuo Ishii
|
||||||
* $Id: mbutils.c,v 1.3 1998/09/01 04:33:22 momjian Exp $ */
|
* $Id: mbutils.c,v 1.4 1998/09/25 01:46:23 momjian Exp $ */
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -201,6 +201,34 @@ pg_mbstrlen_with_len(const unsigned char *mbstr, int limit)
|
|||||||
return (len);
|
return (len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* returns the length of a multi-byte string
|
||||||
|
* (not necessarily NULL terminated)
|
||||||
|
* that is not longer than limit.
|
||||||
|
* this function does not break multi-byte word boundary.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
pg_mbcliplen(const unsigned char *mbstr, int len, int limit)
|
||||||
|
{
|
||||||
|
int clen = 0;
|
||||||
|
int l;
|
||||||
|
|
||||||
|
while (*mbstr && len > 0)
|
||||||
|
{
|
||||||
|
l = pg_mblen(mbstr);
|
||||||
|
if ((clen + l) > limit) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
clen += l;
|
||||||
|
if (clen == limit) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
len -= l;
|
||||||
|
mbstr += l;
|
||||||
|
}
|
||||||
|
return (clen);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* fuctions for utils/init
|
* fuctions for utils/init
|
||||||
*/
|
*/
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $Id: pg_wchar.h,v 1.4 1998/09/01 04:36:34 momjian Exp $ */
|
/* $Id: pg_wchar.h,v 1.5 1998/09/25 01:46:25 momjian Exp $ */
|
||||||
|
|
||||||
#ifndef PG_WCHAR_H
|
#ifndef PG_WCHAR_H
|
||||||
#define PG_WCHAR_H
|
#define PG_WCHAR_H
|
||||||
@ -103,6 +103,7 @@ extern int pg_mule_mblen(const unsigned char *);
|
|||||||
extern int pg_mic_mblen(const unsigned char *);
|
extern int pg_mic_mblen(const unsigned char *);
|
||||||
extern int pg_mbstrlen(const unsigned char *);
|
extern int pg_mbstrlen(const unsigned char *);
|
||||||
extern int pg_mbstrlen_with_len(const unsigned char *, int);
|
extern int pg_mbstrlen_with_len(const unsigned char *, int);
|
||||||
|
extern int pg_mbcliplen(const unsigned char *, int, int);
|
||||||
extern pg_encoding_conv_tbl *pg_get_encent_by_encoding(int);
|
extern pg_encoding_conv_tbl *pg_get_encent_by_encoding(int);
|
||||||
extern bool show_client_encoding(void);
|
extern bool show_client_encoding(void);
|
||||||
extern bool reset_client_encoding(void);
|
extern bool reset_client_encoding(void);
|
||||||
|
Reference in New Issue
Block a user