~vcs-imports/mammoth-replicator/trunk

« back to all changes in this revision

Viewing changes to src/backend/utils/mb/conversion_procs/utf8_and_euc_tw/utf8_and_euc_tw.c

  • Committer: alvherre
  • Date: 2005-12-16 21:24:52 UTC
  • Revision ID: svn-v4:db760fc0-0f08-0410-9d63-cc6633f64896:trunk:1
Initial import of the REL8_0_3 sources from the Pgsql CVS repository.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*-------------------------------------------------------------------------
 
2
 *
 
3
 *        EUC_TW <--> UTF-8
 
4
 *
 
5
 * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
 
6
 * Portions Copyright (c) 1994, Regents of the University of California
 
7
 *
 
8
 * IDENTIFICATION
 
9
 *        $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/utf8_and_euc_tw/utf8_and_euc_tw.c,v 1.9 2004-12-31 22:02:20 pgsql Exp $
 
10
 *
 
11
 *-------------------------------------------------------------------------
 
12
 */
 
13
 
 
14
#include "postgres.h"
 
15
#include "fmgr.h"
 
16
#include "mb/pg_wchar.h"
 
17
#include "../../Unicode/euc_tw_to_utf8.map"
 
18
#include "../../Unicode/utf8_to_euc_tw.map"
 
19
 
 
20
PG_FUNCTION_INFO_V1(euc_tw_to_utf8);
 
21
PG_FUNCTION_INFO_V1(utf8_to_euc_tw);
 
22
 
 
23
extern Datum euc_tw_to_utf8(PG_FUNCTION_ARGS);
 
24
extern Datum utf8_to_euc_tw(PG_FUNCTION_ARGS);
 
25
 
 
26
/* ----------
 
27
 * conv_proc(
 
28
 *              INTEGER,        -- source encoding id
 
29
 *              INTEGER,        -- destination encoding id
 
30
 *              CSTRING,        -- source string (null terminated C string)
 
31
 *              CSTRING,        -- destination string (null terminated C string)
 
32
 *              INTEGER         -- source string length
 
33
 * ) returns VOID;
 
34
 * ----------
 
35
 */
 
36
Datum
 
37
euc_tw_to_utf8(PG_FUNCTION_ARGS)
 
38
{
 
39
        unsigned char *src = PG_GETARG_CSTRING(2);
 
40
        unsigned char *dest = PG_GETARG_CSTRING(3);
 
41
        int                     len = PG_GETARG_INT32(4);
 
42
 
 
43
        Assert(PG_GETARG_INT32(0) == PG_EUC_TW);
 
44
        Assert(PG_GETARG_INT32(1) == PG_UTF8);
 
45
        Assert(len >= 0);
 
46
 
 
47
        LocalToUtf(src, dest, LUmapEUC_TW,
 
48
                  sizeof(LUmapEUC_TW) / sizeof(pg_local_to_utf), PG_EUC_TW, len);
 
49
 
 
50
        PG_RETURN_VOID();
 
51
}
 
52
 
 
53
Datum
 
54
utf8_to_euc_tw(PG_FUNCTION_ARGS)
 
55
{
 
56
        unsigned char *src = PG_GETARG_CSTRING(2);
 
57
        unsigned char *dest = PG_GETARG_CSTRING(3);
 
58
        int                     len = PG_GETARG_INT32(4);
 
59
 
 
60
        Assert(PG_GETARG_INT32(0) == PG_UTF8);
 
61
        Assert(PG_GETARG_INT32(1) == PG_EUC_TW);
 
62
        Assert(len >= 0);
 
63
 
 
64
        UtfToLocal(src, dest, ULmapEUC_TW,
 
65
                           sizeof(ULmapEUC_TW) / sizeof(pg_utf_to_local), len);
 
66
 
 
67
        PG_RETURN_VOID();
 
68
}