OSDN Git Service

Add a bunch of pseudo-types to replace the behavior formerly associated
[pg-rex/syncrep.git] / src / backend / utils / mb / conversion_procs / utf8_and_ascii / utf8_and_ascii.c
1 /*-------------------------------------------------------------------------
2  *
3  *        ASCII <--> UTF-8
4  *
5  * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
6  * Portions Copyright (c) 1994, Regents of the University of California
7  *
8  * IDENTIFICATION
9  *        $Header: /cvsroot/pgsql/src/backend/utils/mb/conversion_procs/utf8_and_ascii/utf8_and_ascii.c,v 1.2 2002/08/22 00:01:45 tgl Exp $
10  *
11  *-------------------------------------------------------------------------
12  */
13
14 #include "postgres.h"
15 #include "fmgr.h"
16 #include "mb/pg_wchar.h"
17
18 PG_FUNCTION_INFO_V1(ascii_to_utf8)
19 PG_FUNCTION_INFO_V1(utf8_to_ascii)
20
21 extern Datum ascii_to_utf8(PG_FUNCTION_ARGS);
22 extern Datum utf8_to_ascii(PG_FUNCTION_ARGS);
23
24 /* ----------
25  * conv_proc(
26  *              INTEGER,        -- source encoding id
27  *              INTEGER,        -- destination encoding id
28  *              CSTRING,        -- source string (null terminated C string)
29  *              CSTRING,        -- destination string (null terminated C string)
30  *              INTEGER         -- source string length
31  * ) returns VOID;
32  * ----------
33  */
34
35 Datum
36 ascii_to_utf8(PG_FUNCTION_ARGS)
37 {
38         unsigned char *src = PG_GETARG_CSTRING(2);
39         unsigned char *dest = PG_GETARG_CSTRING(3);
40         int len = PG_GETARG_INT32(4);
41
42         Assert(PG_GETARG_INT32(0) == PG_SQL_ASCII);
43         Assert(PG_GETARG_INT32(1) == PG_UTF8);
44         Assert(len > 0);
45
46         pg_ascii2mic(src, dest, len);
47
48         PG_RETURN_INT32(0);
49 }
50
51 Datum
52 utf8_to_ascii(PG_FUNCTION_ARGS)
53 {
54         unsigned char *src = PG_GETARG_CSTRING(2);
55         unsigned char *dest = PG_GETARG_CSTRING(3);
56         int len = PG_GETARG_INT32(4);
57
58         Assert(PG_GETARG_INT32(0) == PG_UTF8);
59         Assert(PG_GETARG_INT32(1) == PG_SQL_ASCII);
60         Assert(len > 0);
61
62         pg_mic2ascii(src, dest, len);
63
64         PG_RETURN_INT32(0);
65 }