~ubuntu-branches/ubuntu/natty/postgresql-8.4/natty-updates

« back to all changes in this revision

Viewing changes to src/backend/utils/mb/conversion_procs/utf8_and_johab/utf8_and_johab.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
 *        JOHAB <--> 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/johab_to_utf8.map"
 
18
#include "../../Unicode/utf8_to_johab.map"
 
19
 
 
20
PG_MODULE_MAGIC;
 
21
 
 
22
PG_FUNCTION_INFO_V1(johab_to_utf8);
 
23
PG_FUNCTION_INFO_V1(utf8_to_johab);
 
24
 
 
25
extern Datum johab_to_utf8(PG_FUNCTION_ARGS);
 
26
extern Datum utf8_to_johab(PG_FUNCTION_ARGS);
 
27
 
 
28
/* ----------
 
29
 * conv_proc(
 
30
 *              INTEGER,        -- source encoding id
 
31
 *              INTEGER,        -- destination encoding id
 
32
 *              CSTRING,        -- source string (null terminated C string)
 
33
 *              CSTRING,        -- destination string (null terminated C string)
 
34
 *              INTEGER         -- source string length
 
35
 * ) returns VOID;
 
36
 * ----------
 
37
 */
 
38
Datum
 
39
johab_to_utf8(PG_FUNCTION_ARGS)
 
40
{
 
41
        unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
 
42
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
 
43
        int                     len = PG_GETARG_INT32(4);
 
44
 
 
45
        CHECK_ENCODING_CONVERSION_ARGS(PG_JOHAB, PG_UTF8);
 
46
 
 
47
        LocalToUtf(src, dest, LUmapJOHAB, NULL,
 
48
                         sizeof(LUmapJOHAB) / sizeof(pg_local_to_utf), 0, PG_JOHAB, len);
 
49
 
 
50
        PG_RETURN_VOID();
 
51
}
 
52
 
 
53
Datum
 
54
utf8_to_johab(PG_FUNCTION_ARGS)
 
55
{
 
56
        unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
 
57
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
 
58
        int                     len = PG_GETARG_INT32(4);
 
59
 
 
60
        CHECK_ENCODING_CONVERSION_ARGS(PG_UTF8, PG_JOHAB);
 
61
 
 
62
        UtfToLocal(src, dest, ULmapJOHAB, NULL,
 
63
                         sizeof(ULmapJOHAB) / sizeof(pg_utf_to_local), 0, PG_JOHAB, len);
 
64
 
 
65
        PG_RETURN_VOID();
 
66
}