Header And Logo

PostgreSQL
| The world's most advanced open source database.

utf8_and_big5.c

Go to the documentation of this file.
00001 /*-------------------------------------------------------------------------
00002  *
00003  *    BIG5 <--> UTF8
00004  *
00005  * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
00006  * Portions Copyright (c) 1994, Regents of the University of California
00007  *
00008  * IDENTIFICATION
00009  *    src/backend/utils/mb/conversion_procs/utf8_and_big5/utf8_and_big5.c
00010  *
00011  *-------------------------------------------------------------------------
00012  */
00013 
00014 #include "postgres.h"
00015 #include "fmgr.h"
00016 #include "mb/pg_wchar.h"
00017 #include "../../Unicode/big5_to_utf8.map"
00018 #include "../../Unicode/utf8_to_big5.map"
00019 
00020 PG_MODULE_MAGIC;
00021 
00022 PG_FUNCTION_INFO_V1(big5_to_utf8);
00023 PG_FUNCTION_INFO_V1(utf8_to_big5);
00024 
00025 extern Datum big5_to_utf8(PG_FUNCTION_ARGS);
00026 extern Datum utf8_to_big5(PG_FUNCTION_ARGS);
00027 
00028 /* ----------
00029  * conv_proc(
00030  *      INTEGER,    -- source encoding id
00031  *      INTEGER,    -- destination encoding id
00032  *      CSTRING,    -- source string (null terminated C string)
00033  *      CSTRING,    -- destination string (null terminated C string)
00034  *      INTEGER     -- source string length
00035  * ) returns VOID;
00036  * ----------
00037  */
00038 Datum
00039 big5_to_utf8(PG_FUNCTION_ARGS)
00040 {
00041     unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
00042     unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
00043     int         len = PG_GETARG_INT32(4);
00044 
00045     CHECK_ENCODING_CONVERSION_ARGS(PG_BIG5, PG_UTF8);
00046 
00047     LocalToUtf(src, dest, LUmapBIG5, NULL,
00048                sizeof(LUmapBIG5) / sizeof(pg_local_to_utf), 0, PG_BIG5, len);
00049 
00050     PG_RETURN_VOID();
00051 }
00052 
00053 Datum
00054 utf8_to_big5(PG_FUNCTION_ARGS)
00055 {
00056     unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
00057     unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
00058     int         len = PG_GETARG_INT32(4);
00059 
00060     CHECK_ENCODING_CONVERSION_ARGS(PG_UTF8, PG_BIG5);
00061 
00062     UtfToLocal(src, dest, ULmapBIG5, NULL,
00063                sizeof(ULmapBIG5) / sizeof(pg_utf_to_local), 0, PG_BIG5, len);
00064 
00065     PG_RETURN_VOID();
00066 }