8
8
*
9
9
*
10
10
* IDENTIFICATION
11
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/varchar.c,v 1.60.2.1 2000/07/07 21:29:57 tgl Exp $
11
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/varchar.c,v 1.60.2.2 2000/11/02 05:11:42 ishii Exp $
12
12
*
13
13
*-------------------------------------------------------------------------
14
14
*/
@@ -79,7 +79,17 @@ bpcharin(char *s, int dummy, int32 atttypmod)
79
79
atttypmod = len + VARHDRSZ;
80
80
}
81
81
else
82
+ #ifdef MULTIBYTE
83
+ {
84
+ /*
85
+ * truncate multi-byte string preserving multi-byte
86
+ * boundary
87
+ */
88
+ len = pg_mbcliplen(s, atttypmod - VARHDRSZ, atttypmod - VARHDRSZ);
89
+ }
90
+ #else
82
91
len = atttypmod - VARHDRSZ;
92
+ #endif
83
93
84
94
result = (char *) palloc(atttypmod);
85
95
VARSIZE(result) = atttypmod;
@@ -96,7 +106,11 @@ bpcharin(char *s, int dummy, int32 atttypmod)
96
106
#endif
97
107
98
108
/* blank pad the string if necessary */
109
+ #ifdef MULTIBYTE
110
+ for (; i < atttypmod - VARHDRSZ; i++)
111
+ #else
99
112
for (; i < len; i++)
113
+ #endif
100
114
*r++ = ' ';
101
115
return result;
102
116
}
@@ -161,7 +175,7 @@ bpchar(char *s, int32 len)
161
175
#ifdef MULTIBYTE
162
176
163
177
/*
164
- * truncate multi-byte string in a way not to break multi-byte
178
+ * truncate multi-byte string preserving multi-byte
165
179
* boundary
166
180
*/
167
181
if (VARSIZE(s) > len)
@@ -326,7 +340,14 @@ varcharin(char *s, int dummy, int32 atttypmod)
326
340
327
341
len = strlen(s) + VARHDRSZ;
328
342
if (atttypmod >= (int32) VARHDRSZ && len > atttypmod)
329
- len = atttypmod; /* clip the string at max length */
343
+ {
344
+ /* clip the string at max length */
345
+ #ifdef MULTIBYTE
346
+ len = pg_mbcliplen(s, len - VARHDRSZ, atttypmod - VARHDRSZ) + VARHDRSZ;
347
+ #else
348
+ len = atttypmod;
349
+ #endif
350
+ }
330
351
331
352
result = (char *) palloc(len);
332
353
VARSIZE(result) = len;
@@ -388,7 +409,7 @@ varchar(char *s, int32 slen)
388
409
#ifdef MULTIBYTE
389
410
390
411
/*
391
- * truncate multi-byte string in a way not to break multi-byte
412
+ * truncate multi-byte string preserving the multi-byte
392
413
* boundary
393
414
*/
394
415
len = pg_mbcliplen(VARDATA(s), slen - VARHDRSZ, slen - VARHDRSZ);
0 commit comments