Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf52e734

Browse files
committed
MB patches from Tatsuo Ishii
1 parent31fea97 commitf52e734

File tree

3 files changed

+46
-3
lines changed

3 files changed

+46
-3
lines changed

‎src/backend/utils/adt/varchar.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/varchar.c,v 1.39 1998/09/01 04:32:53 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/varchar.c,v 1.40 1998/09/25 01:46:21 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -147,7 +147,14 @@ bpchar(char *s, int32 len)
147147
if ((len==-1)|| (len==VARSIZE(s)))
148148
returns;
149149

150+
#ifdefMULTIBYTE
151+
/* truncate multi-byte string in a way not to break
152+
multi-byte boundary */
153+
rlen=pg_mbcliplen(VARDATA(s),len-VARHDRSZ,len-VARHDRSZ);
154+
len=rlen+VARHDRSZ;
155+
#else
150156
rlen=len-VARHDRSZ;
157+
#endif
151158

152159
if (rlen>4096)
153160
elog(ERROR,"bpchar: length of char() must be less than 4096");
@@ -367,7 +374,14 @@ varchar(char *s, int32 slen)
367374

368375
/* only reach here if we need to truncate string... */
369376

377+
#ifdefMULTIBYTE
378+
/* truncate multi-byte string in a way not to break
379+
multi-byte boundary */
380+
len=pg_mbcliplen(VARDATA(s),slen-VARHDRSZ,slen-VARHDRSZ);
381+
slen=len+VARHDRSZ;
382+
#else
370383
len=slen-VARHDRSZ;
384+
#endif
371385

372386
if (len>4096)
373387
elog(ERROR,"varchar: length of varchar() must be less than 4096");

‎src/backend/utils/mb/mbutils.c

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* client encoding and server internal encoding.
44
* (currently mule internal code (mic) is used)
55
* Tatsuo Ishii
6-
* $Id: mbutils.c,v 1.3 1998/09/01 04:33:22 momjian Exp $ */
6+
* $Id: mbutils.c,v 1.4 1998/09/25 01:46:23 momjian Exp $ */
77

88
#include<stdio.h>
99
#include<string.h>
@@ -201,6 +201,34 @@ pg_mbstrlen_with_len(const unsigned char *mbstr, int limit)
201201
return (len);
202202
}
203203

204+
/*
205+
* returns the length of a multi-byte string
206+
* (not necessarily NULL terminated)
207+
* that is not longer than limit.
208+
* this function does not break multi-byte word boundary.
209+
*/
210+
int
211+
pg_mbcliplen(constunsignedchar*mbstr,intlen,intlimit)
212+
{
213+
intclen=0;
214+
intl;
215+
216+
while (*mbstr&&len>0)
217+
{
218+
l=pg_mblen(mbstr);
219+
if ((clen+l)>limit) {
220+
break;
221+
}
222+
clen+=l;
223+
if (clen==limit) {
224+
break;
225+
}
226+
len-=l;
227+
mbstr+=l;
228+
}
229+
return (clen);
230+
}
231+
204232
/*
205233
* fuctions for utils/init
206234
*/

‎src/include/mb/pg_wchar.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $Id: pg_wchar.h,v 1.4 1998/09/01 04:36:34 momjian Exp $ */
1+
/* $Id: pg_wchar.h,v 1.5 1998/09/25 01:46:25 momjian Exp $ */
22

33
#ifndefPG_WCHAR_H
44
#definePG_WCHAR_H
@@ -103,6 +103,7 @@ extern intpg_mule_mblen(const unsigned char *);
103103
externintpg_mic_mblen(constunsignedchar*);
104104
externintpg_mbstrlen(constunsignedchar*);
105105
externintpg_mbstrlen_with_len(constunsignedchar*,int);
106+
externintpg_mbcliplen(constunsignedchar*,int,int);
106107
externpg_encoding_conv_tbl*pg_get_encent_by_encoding(int);
107108
externboolshow_client_encoding(void);
108109
externboolreset_client_encoding(void);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp