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

Commit403e522

Browse files
committed
Add missing files from Karel, tip from Jan.
1 parent317ff59 commit403e522

File tree

2 files changed

+183
-0
lines changed

2 files changed

+183
-0
lines changed

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

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
2+
/* -----------------------------------------------------------------------
3+
* ascii.c
4+
*
5+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ascii.c,v 1.1 2000/08/04 20:22:51 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+
statictext*encode_to_ascii(text*data,intenc);
23+
24+
/* ----------
25+
* to_ascii
26+
* ----------
27+
*/
28+
char*
29+
pg_to_ascii(unsignedchar*src,unsignedchar*src_end,unsignedchar*desc,intenc)
30+
{
31+
unsignedchar*x=NULL;
32+
unsignedchar*ascii=NULL ;
33+
intrange=0;
34+
35+
/*
36+
* relevant start for an encoding
37+
*/
38+
#defineRANGE_128128
39+
#defineRANGE_160160
40+
41+
42+
if (enc==LATIN1)
43+
{
44+
/* ----------
45+
* ISO-8859-1 <range: 160 -- 255>
46+
* ----------
47+
*/
48+
ascii=" cL Y \"Ca -R 'u ., ?AAAAAAACEEEEIIII NOOOOOxOUUUUYTBaaaaaaaceeeeiiii nooooo/ouuuuyty";
49+
range=RANGE_160;
50+
}
51+
elseif (enc==LATIN2)
52+
{
53+
/* ----------
54+
* ISO-8859-2 <range: 160 -- 255>
55+
* ----------
56+
*/
57+
ascii=" A L LS \"SSTZ-ZZ a,l'ls ,sstz\"zzRAAAALCCCEEEEIIDDNNOOOOxRUUUUYTBraaaalccceeeeiiddnnoooo/ruuuuyt.";
58+
range=RANGE_160;
59+
}
60+
elseif (enc==WIN1250)
61+
{
62+
/* ----------
63+
* Window CP1250 <range: 128 -- 255>
64+
* ----------
65+
*/
66+
ascii=" ' \" %S<STZZ `'\"\".-- s>stzz L A \"CS -RZ ,l'u .,as L\"lzRAAAALCCCEEEEIIDDNNOOOOxRUUUUYTBraaaalccceeeeiiddnnoooo/ruuuuyt ";
67+
range=RANGE_128;
68+
}
69+
else
70+
{
71+
elog(ERROR,"pg_to_ascii(): unsupported encoding from %s",
72+
pg_encoding_to_char(enc));
73+
}
74+
75+
/* ----------
76+
* Encode
77+
* ----------
78+
*/
79+
for (x=src;x <=src_end;x++)
80+
{
81+
if (*x<128)
82+
*desc++=*x;
83+
elseif (*x<range)
84+
*desc++=' ';/* bogus 128 to 'range' */
85+
else
86+
*desc++=ascii[*x-range];
87+
}
88+
89+
returndesc;
90+
}
91+
92+
/* ----------
93+
* encode text
94+
* ----------
95+
*/
96+
statictext*
97+
encode_to_ascii(text*data,intenc)
98+
{
99+
pg_to_ascii(
100+
(unsignedchar*)VARDATA(data),/* src */
101+
VARDATA(data)+VARSIZE(data),/* src end */
102+
(unsignedchar*)VARDATA(data),/* desc */
103+
enc);/* encoding */
104+
105+
returndata;
106+
}
107+
108+
/* ----------
109+
* convert to ASCII - enc is set as 'name' arg.
110+
* ----------
111+
*/
112+
Datum
113+
to_ascii_encname(PG_FUNCTION_ARGS)
114+
{
115+
PG_RETURN_TEXT_P
116+
(
117+
encode_to_ascii
118+
(
119+
PG_GETARG_TEXT_P_COPY(0),
120+
pg_char_to_encoding(NameStr(*PG_GETARG_NAME(1)) )
121+
)
122+
);
123+
}
124+
125+
/* ----------
126+
* convert to ASCII - enc is set as int4
127+
* ----------
128+
*/
129+
Datum
130+
to_ascii_enc(PG_FUNCTION_ARGS)
131+
{
132+
PG_RETURN_TEXT_P
133+
(
134+
encode_to_ascii
135+
(
136+
PG_GETARG_TEXT_P_COPY(0),
137+
PG_GETARG_INT32(1)
138+
)
139+
);
140+
}
141+
142+
/* ----------
143+
* convert to ASCII - current enc is DatabaseEncoding
144+
* ----------
145+
*/
146+
Datum
147+
to_ascii_default(PG_FUNCTION_ARGS)
148+
{
149+
PG_RETURN_TEXT_P
150+
(
151+
encode_to_ascii
152+
(
153+
PG_GETARG_TEXT_P_COPY(0),
154+
GetDatabaseEncoding()
155+
)
156+
);
157+
}
158+
159+

‎src/include/utils/ascii.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
/* -----------------------------------------------------------------------
3+
* ascii.h
4+
*
5+
* $Id: ascii.h,v 1.1 2000/08/04 20:22:52 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+
externchar*pg_to_ascii(unsignedchar*src,unsignedchar*src_end,
22+
unsignedchar*desc,intenc);
23+
24+
#endif

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp