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

Commit75b6104

Browse files
committed
> I had to back out the patch. It only compiles with multi-byte enabled.
Ooops, I forget... here it is again.> > > If encoding is not supported returns ERROR. and if multibyte not enabled too.... Thanks. Karel~
1 parent4ebb751 commit75b6104

File tree

4 files changed

+240
-3
lines changed

4 files changed

+240
-3
lines changed

‎src/backend/utils/adt/Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#
22
# Makefile for utils/adt
33
#
4-
# $Header: /cvsroot/pgsql/src/backend/utils/adt/Makefile,v 1.43 2000/08/04 20:46:43 momjian Exp $
4+
# $Header: /cvsroot/pgsql/src/backend/utils/adt/Makefile,v 1.44 2000/08/05 14:59:17 momjian Exp $
55
#
66

77
subdir = src/backend/utils/adt
@@ -23,7 +23,8 @@ OBJS = acl.o arrayfuncs.o arrayutils.o bool.o cash.o char.o \
2323
regexp.o regproc.o ruleutils.o selfuncs.o sets.o\
2424
tid.o timestamp.o varbit.o varchar.o varlena.o version.o\
2525
network.o mac.o inet_net_ntop.o inet_net_pton.o\
26-
ri_triggers.o pg_lzcompress.o pg_locale.o formatting.o
26+
ri_triggers.o pg_lzcompress.o pg_locale.o formatting.o\
27+
ascii.o
2728

2829
all: SUBSYS.o
2930

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

Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
2+
/* -----------------------------------------------------------------------
3+
* ascii.c
4+
*
5+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ascii.c,v 1.3 2000/08/05 14:59:17 momjian Exp $
6+
*
7+
* Portions Copyright (c) 1999-2000, PostgreSQL, Inc
8+
*
9+
*
10+
* TO_ASCII()
11+
*
12+
* The PostgreSQL routine for string to ascii conversion.
13+
*
14+
* -----------------------------------------------------------------------
15+
*/
16+
17+
#include"postgres.h"
18+
#include"utils/builtins.h"
19+
#include"mb/pg_wchar.h"
20+
#include"utils/ascii.h"
21+
22+
/* ----------
23+
* even if MULTIBYTE is not enabled, these functions are necessary
24+
* since pg_proc.h has references to them.
25+
* ----------
26+
*/
27+
#ifndefMULTIBYTE
28+
29+
staticvoidmultibyte_error(void);
30+
31+
staticvoid
32+
multibyte_error()
33+
{
34+
elog(ERROR,"multibyte not supported.");
35+
}
36+
37+
Datum
38+
to_ascii_encname(PG_FUNCTION_ARGS)
39+
{
40+
multibyte_error();
41+
}
42+
43+
Datum
44+
to_ascii_enc(PG_FUNCTION_ARGS)
45+
{
46+
multibyte_error();
47+
}
48+
49+
Datum
50+
to_ascii_default(PG_FUNCTION_ARGS)
51+
{
52+
multibyte_error();
53+
}
54+
55+
56+
#else/* with MULTIBYTE */
57+
58+
59+
/* ----------
60+
* even if MULTIBYTE is enabled
61+
* ----------
62+
*/
63+
64+
statictext*encode_to_ascii(text*data,intenc);
65+
66+
/* ----------
67+
* to_ascii
68+
* ----------
69+
*/
70+
char*
71+
pg_to_ascii(unsignedchar*src,unsignedchar*src_end,unsignedchar*desc,intenc)
72+
{
73+
unsignedchar*x=NULL;
74+
unsignedchar*ascii=NULL ;
75+
intrange=0;
76+
77+
/*
78+
* relevant start for an encoding
79+
*/
80+
#defineRANGE_128128
81+
#defineRANGE_160160
82+
83+
84+
if (enc==LATIN1)
85+
{
86+
/* ----------
87+
* ISO-8859-1 <range: 160 -- 255>
88+
* ----------
89+
*/
90+
ascii=" cL Y \"Ca -R 'u ., ?AAAAAAACEEEEIIII NOOOOOxOUUUUYTBaaaaaaaceeeeiiii nooooo/ouuuuyty";
91+
range=RANGE_160;
92+
}
93+
elseif (enc==LATIN2)
94+
{
95+
/* ----------
96+
* ISO-8859-2 <range: 160 -- 255>
97+
* ----------
98+
*/
99+
ascii=" A L LS \"SSTZ-ZZ a,l'ls ,sstz\"zzRAAAALCCCEEEEIIDDNNOOOOxRUUUUYTBraaaalccceeeeiiddnnoooo/ruuuuyt.";
100+
range=RANGE_160;
101+
}
102+
elseif (enc==WIN1250)
103+
{
104+
/* ----------
105+
* Window CP1250 <range: 128 -- 255>
106+
* ----------
107+
*/
108+
ascii=" ' \" %S<STZZ `'\"\".-- s>stzz L A \"CS -RZ ,l'u .,as L\"lzRAAAALCCCEEEEIIDDNNOOOOxRUUUUYTBraaaalccceeeeiiddnnoooo/ruuuuyt ";
109+
range=RANGE_128;
110+
}
111+
else
112+
{
113+
elog(ERROR,"pg_to_ascii(): unsupported encoding from %s",
114+
pg_encoding_to_char(enc));
115+
}
116+
117+
/* ----------
118+
* Encode
119+
* ----------
120+
*/
121+
for (x=src;x <=src_end;x++)
122+
{
123+
if (*x<128)
124+
*desc++=*x;
125+
elseif (*x<range)
126+
*desc++=' ';/* bogus 128 to 'range' */
127+
else
128+
*desc++=ascii[*x-range];
129+
}
130+
131+
returndesc;
132+
}
133+
134+
/* ----------
135+
* encode text
136+
* ----------
137+
*/
138+
statictext*
139+
encode_to_ascii(text*data,intenc)
140+
{
141+
pg_to_ascii(
142+
(unsignedchar*)VARDATA(data),/* src */
143+
VARDATA(data)+VARSIZE(data),/* src end */
144+
(unsignedchar*)VARDATA(data),/* desc */
145+
enc);/* encoding */
146+
147+
returndata;
148+
}
149+
150+
/* ----------
151+
* convert to ASCII - enc is set as 'name' arg.
152+
* ----------
153+
*/
154+
Datum
155+
to_ascii_encname(PG_FUNCTION_ARGS)
156+
{
157+
PG_RETURN_TEXT_P
158+
(
159+
encode_to_ascii
160+
(
161+
PG_GETARG_TEXT_P_COPY(0),
162+
pg_char_to_encoding(NameStr(*PG_GETARG_NAME(1)) )
163+
)
164+
);
165+
}
166+
167+
/* ----------
168+
* convert to ASCII - enc is set as int4
169+
* ----------
170+
*/
171+
Datum
172+
to_ascii_enc(PG_FUNCTION_ARGS)
173+
{
174+
PG_RETURN_TEXT_P
175+
(
176+
encode_to_ascii
177+
(
178+
PG_GETARG_TEXT_P_COPY(0),
179+
PG_GETARG_INT32(1)
180+
)
181+
);
182+
}
183+
184+
/* ----------
185+
* convert to ASCII - current enc is DatabaseEncoding
186+
* ----------
187+
*/
188+
Datum
189+
to_ascii_default(PG_FUNCTION_ARGS)
190+
{
191+
PG_RETURN_TEXT_P
192+
(
193+
encode_to_ascii
194+
(
195+
PG_GETARG_TEXT_P_COPY(0),
196+
GetDatabaseEncoding()
197+
)
198+
);
199+
}
200+
201+
#endif/* MULTIBYTE */

‎src/include/catalog/pg_proc.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: pg_proc.h,v 1.159 2000/08/04 20:46:43 momjian Exp $
10+
* $Id: pg_proc.h,v 1.160 2000/08/05 14:59:19 momjian Exp $
1111
*
1212
* NOTES
1313
* The script catalog/genbki.sh reads this file and generates .bki
@@ -2442,6 +2442,14 @@ DESCR("aggregate transition function");
24422442
DATA(insertOID=1844 (interval_avgPGUID12fttt1f1186"1187"10000100interval_avg- ));
24432443
DESCR("AVG aggregate final function");
24442444

2445+
/* To ASCII conversion */
2446+
DATA(insertOID=1845 (to_asciiPGUID12fttt1f25"25"10000100to_ascii_default- ));
2447+
DESCR("encode text from DB encoding to ASCII text");
2448+
DATA(insertOID=1846 (to_asciiPGUID12fttt2f25"25 23"10000100to_ascii_enc- ));
2449+
DESCR("encode text from encoding to ASCII text");
2450+
DATA(insertOID=1847 (to_asciiPGUID12fttt2f25"25 19"10000100to_ascii_encname- ));
2451+
DESCR("encode text from encoding to ASCII text");
2452+
24452453
DATA(insertOID=1850 (int28eqPGUID12fttt2f16"21 20"10000100int28eq- ));
24462454
DESCR("equal");
24472455
DATA(insertOID=1851 (int28nePGUID12fttt2f16"21 20"10000100int28ne- ));

‎src/include/utils/ascii.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
/* -----------------------------------------------------------------------
3+
* ascii.h
4+
*
5+
* $Id: ascii.h,v 1.3 2000/08/05 14:59:29 momjian Exp $
6+
*
7+
* Portions Copyright (c) 1999-2000, PostgreSQL, Inc
8+
*
9+
* -----------------------------------------------------------------------
10+
*/
11+
12+
#ifndef_ASCII_H_
13+
#define_ASCII_H_
14+
15+
#include"fmgr.h"
16+
17+
externDatumto_ascii_encname(PG_FUNCTION_ARGS);
18+
externDatumto_ascii_enc(PG_FUNCTION_ARGS);
19+
externDatumto_ascii_default(PG_FUNCTION_ARGS);
20+
21+
#ifdefMULTIBYTE
22+
23+
externchar*pg_to_ascii(unsignedchar*src,unsignedchar*src_end,
24+
unsignedchar*desc,intenc);
25+
#endif/* MULTIBYTE */
26+
27+
#endif/* _ASCII_H_ */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp