~ubuntu-branches/ubuntu/hardy/postgresql-8.4/hardy-backports

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2009-03-20 12:00:13 UTC
  • Revision ID: james.westby@ubuntu.com-20090320120013-hogj7egc5mjncc5g
Tags: upstream-8.4~0cvs20090328
ImportĀ upstreamĀ versionĀ 8.4~0cvs20090328

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*-------------------------------------------------------------------------
 
2
 *
 
3
 *        SHIFT_JIS_2004 <--> UTF8
 
4
 *
 
5
 * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
 
6
 * Portions Copyright (c) 1994, Regents of the University of California
 
7
 *
 
8
 * IDENTIFICATION
 
9
 *        $PostgreSQL$
 
10
 *
 
11
 *-------------------------------------------------------------------------
 
12
 */
 
13
 
 
14
#include "postgres.h"
 
15
#include "fmgr.h"
 
16
#include "mb/pg_wchar.h"
 
17
#include "../../Unicode/shift_jis_2004_to_utf8.map"
 
18
#include "../../Unicode/utf8_to_shift_jis_2004.map"
 
19
#include "../../Unicode/shift_jis_2004_to_utf8_combined.map"
 
20
#include "../../Unicode/utf8_to_shift_jis_2004_combined.map"
 
21
 
 
22
PG_MODULE_MAGIC;
 
23
 
 
24
PG_FUNCTION_INFO_V1(shift_jis_2004_to_utf8);
 
25
PG_FUNCTION_INFO_V1(utf8_to_shift_jis_2004);
 
26
 
 
27
extern Datum shift_jis_2004_to_utf8(PG_FUNCTION_ARGS);
 
28
extern Datum utf8_to_shift_jis_2004(PG_FUNCTION_ARGS);
 
29
 
 
30
/* ----------
 
31
 * conv_proc(
 
32
 *              INTEGER,        -- source encoding id
 
33
 *              INTEGER,        -- destination encoding id
 
34
 *              CSTRING,        -- source string (null terminated C string)
 
35
 *              CSTRING,        -- destination string (null terminated C string)
 
36
 *              INTEGER         -- source string length
 
37
 * ) returns VOID;
 
38
 * ----------
 
39
 */
 
40
Datum
 
41
shift_jis_2004_to_utf8(PG_FUNCTION_ARGS)
 
42
{
 
43
        unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
 
44
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
 
45
        int                     len = PG_GETARG_INT32(4);
 
46
 
 
47
        CHECK_ENCODING_CONVERSION_ARGS(PG_SHIFT_JIS_2004, PG_UTF8);
 
48
 
 
49
        LocalToUtf(src, dest, LUmapSHIFT_JIS_2004, LUmapSHIFT_JIS_2004_combined,
 
50
                           sizeof(LUmapSHIFT_JIS_2004) / sizeof(pg_local_to_utf),
 
51
         sizeof(LUmapSHIFT_JIS_2004_combined) / sizeof(pg_local_to_utf_combined),
 
52
                           PG_SHIFT_JIS_2004, len);
 
53
 
 
54
        PG_RETURN_VOID();
 
55
}
 
56
 
 
57
Datum
 
58
utf8_to_shift_jis_2004(PG_FUNCTION_ARGS)
 
59
{
 
60
        unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
 
61
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
 
62
        int                     len = PG_GETARG_INT32(4);
 
63
 
 
64
        CHECK_ENCODING_CONVERSION_ARGS(PG_UTF8, PG_SHIFT_JIS_2004);
 
65
 
 
66
        UtfToLocal(src, dest, ULmapSHIFT_JIS_2004, ULmapSHIFT_JIS_2004_combined,
 
67
                           sizeof(ULmapSHIFT_JIS_2004) / sizeof(pg_utf_to_local),
 
68
         sizeof(ULmapSHIFT_JIS_2004_combined) / sizeof(pg_utf_to_local_combined),
 
69
                           PG_SHIFT_JIS_2004, len);
 
70
 
 
71
        PG_RETURN_VOID();
 
72
}