Header And Logo

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

utf8_and_sjis2004.c

Go to the documentation of this file.
00001 /*-------------------------------------------------------------------------
00002  *
00003  *    SHIFT_JIS_2004 <--> 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_sjis2004/utf8_and_sjis2004.c
00010  *
00011  *-------------------------------------------------------------------------
00012  */
00013 
00014 #include "postgres.h"
00015 #include "fmgr.h"
00016 #include "mb/pg_wchar.h"
00017 #include "../../Unicode/shift_jis_2004_to_utf8.map"
00018 #include "../../Unicode/utf8_to_shift_jis_2004.map"
00019 #include "../../Unicode/shift_jis_2004_to_utf8_combined.map"
00020 #include "../../Unicode/utf8_to_shift_jis_2004_combined.map"
00021 
00022 PG_MODULE_MAGIC;
00023 
00024 PG_FUNCTION_INFO_V1(shift_jis_2004_to_utf8);
00025 PG_FUNCTION_INFO_V1(utf8_to_shift_jis_2004);
00026 
00027 extern Datum shift_jis_2004_to_utf8(PG_FUNCTION_ARGS);
00028 extern Datum utf8_to_shift_jis_2004(PG_FUNCTION_ARGS);
00029 
00030 /* ----------
00031  * conv_proc(
00032  *      INTEGER,    -- source encoding id
00033  *      INTEGER,    -- destination encoding id
00034  *      CSTRING,    -- source string (null terminated C string)
00035  *      CSTRING,    -- destination string (null terminated C string)
00036  *      INTEGER     -- source string length
00037  * ) returns VOID;
00038  * ----------
00039  */
00040 Datum
00041 shift_jis_2004_to_utf8(PG_FUNCTION_ARGS)
00042 {
00043     unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
00044     unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
00045     int         len = PG_GETARG_INT32(4);
00046 
00047     CHECK_ENCODING_CONVERSION_ARGS(PG_SHIFT_JIS_2004, PG_UTF8);
00048 
00049     LocalToUtf(src, dest, LUmapSHIFT_JIS_2004, LUmapSHIFT_JIS_2004_combined,
00050                sizeof(LUmapSHIFT_JIS_2004) / sizeof(pg_local_to_utf),
00051      sizeof(LUmapSHIFT_JIS_2004_combined) / sizeof(pg_local_to_utf_combined),
00052                PG_SHIFT_JIS_2004, len);
00053 
00054     PG_RETURN_VOID();
00055 }
00056 
00057 Datum
00058 utf8_to_shift_jis_2004(PG_FUNCTION_ARGS)
00059 {
00060     unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
00061     unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
00062     int         len = PG_GETARG_INT32(4);
00063 
00064     CHECK_ENCODING_CONVERSION_ARGS(PG_UTF8, PG_SHIFT_JIS_2004);
00065 
00066     UtfToLocal(src, dest, ULmapSHIFT_JIS_2004, ULmapSHIFT_JIS_2004_combined,
00067                sizeof(ULmapSHIFT_JIS_2004) / sizeof(pg_utf_to_local),
00068      sizeof(ULmapSHIFT_JIS_2004_combined) / sizeof(pg_utf_to_local_combined),
00069                PG_SHIFT_JIS_2004, len);
00070 
00071     PG_RETURN_VOID();
00072 }