Header And Logo

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

latin_and_mic.c

Go to the documentation of this file.
00001 /*-------------------------------------------------------------------------
00002  *
00003  *    LATINn and MULE_INTERNAL
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/latin_and_mic/latin_and_mic.c
00010  *
00011  *-------------------------------------------------------------------------
00012  */
00013 
00014 #include "postgres.h"
00015 #include "fmgr.h"
00016 #include "mb/pg_wchar.h"
00017 
00018 PG_MODULE_MAGIC;
00019 
00020 PG_FUNCTION_INFO_V1(latin1_to_mic);
00021 PG_FUNCTION_INFO_V1(mic_to_latin1);
00022 PG_FUNCTION_INFO_V1(latin3_to_mic);
00023 PG_FUNCTION_INFO_V1(mic_to_latin3);
00024 PG_FUNCTION_INFO_V1(latin4_to_mic);
00025 PG_FUNCTION_INFO_V1(mic_to_latin4);
00026 
00027 extern Datum latin1_to_mic(PG_FUNCTION_ARGS);
00028 extern Datum mic_to_latin1(PG_FUNCTION_ARGS);
00029 extern Datum latin3_to_mic(PG_FUNCTION_ARGS);
00030 extern Datum mic_to_latin3(PG_FUNCTION_ARGS);
00031 extern Datum latin4_to_mic(PG_FUNCTION_ARGS);
00032 extern Datum mic_to_latin4(PG_FUNCTION_ARGS);
00033 
00034 /* ----------
00035  * conv_proc(
00036  *      INTEGER,    -- source encoding id
00037  *      INTEGER,    -- destination encoding id
00038  *      CSTRING,    -- source string (null terminated C string)
00039  *      CSTRING,    -- destination string (null terminated C string)
00040  *      INTEGER     -- source string length
00041  * ) returns VOID;
00042  * ----------
00043  */
00044 
00045 static void latin12mic(const unsigned char *l, unsigned char *p, int len);
00046 static void mic2latin1(const unsigned char *mic, unsigned char *p, int len);
00047 static void latin32mic(const unsigned char *l, unsigned char *p, int len);
00048 static void mic2latin3(const unsigned char *mic, unsigned char *p, int len);
00049 static void latin42mic(const unsigned char *l, unsigned char *p, int len);
00050 static void mic2latin4(const unsigned char *mic, unsigned char *p, int len);
00051 
00052 Datum
00053 latin1_to_mic(PG_FUNCTION_ARGS)
00054 {
00055     unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
00056     unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
00057     int         len = PG_GETARG_INT32(4);
00058 
00059     CHECK_ENCODING_CONVERSION_ARGS(PG_LATIN1, PG_MULE_INTERNAL);
00060 
00061     latin12mic(src, dest, len);
00062 
00063     PG_RETURN_VOID();
00064 }
00065 
00066 Datum
00067 mic_to_latin1(PG_FUNCTION_ARGS)
00068 {
00069     unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
00070     unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
00071     int         len = PG_GETARG_INT32(4);
00072 
00073     CHECK_ENCODING_CONVERSION_ARGS(PG_MULE_INTERNAL, PG_LATIN1);
00074 
00075     mic2latin1(src, dest, len);
00076 
00077     PG_RETURN_VOID();
00078 }
00079 
00080 Datum
00081 latin3_to_mic(PG_FUNCTION_ARGS)
00082 {
00083     unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
00084     unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
00085     int         len = PG_GETARG_INT32(4);
00086 
00087     CHECK_ENCODING_CONVERSION_ARGS(PG_LATIN3, PG_MULE_INTERNAL);
00088 
00089     latin32mic(src, dest, len);
00090 
00091     PG_RETURN_VOID();
00092 }
00093 
00094 Datum
00095 mic_to_latin3(PG_FUNCTION_ARGS)
00096 {
00097     unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
00098     unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
00099     int         len = PG_GETARG_INT32(4);
00100 
00101     CHECK_ENCODING_CONVERSION_ARGS(PG_MULE_INTERNAL, PG_LATIN3);
00102 
00103     mic2latin3(src, dest, len);
00104 
00105     PG_RETURN_VOID();
00106 }
00107 
00108 Datum
00109 latin4_to_mic(PG_FUNCTION_ARGS)
00110 {
00111     unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
00112     unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
00113     int         len = PG_GETARG_INT32(4);
00114 
00115     CHECK_ENCODING_CONVERSION_ARGS(PG_LATIN4, PG_MULE_INTERNAL);
00116 
00117     latin42mic(src, dest, len);
00118 
00119     PG_RETURN_VOID();
00120 }
00121 
00122 Datum
00123 mic_to_latin4(PG_FUNCTION_ARGS)
00124 {
00125     unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
00126     unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
00127     int         len = PG_GETARG_INT32(4);
00128 
00129     CHECK_ENCODING_CONVERSION_ARGS(PG_MULE_INTERNAL, PG_LATIN4);
00130 
00131     mic2latin4(src, dest, len);
00132 
00133     PG_RETURN_VOID();
00134 }
00135 
00136 static void
00137 latin12mic(const unsigned char *l, unsigned char *p, int len)
00138 {
00139     latin2mic(l, p, len, LC_ISO8859_1, PG_LATIN1);
00140 }
00141 
00142 static void
00143 mic2latin1(const unsigned char *mic, unsigned char *p, int len)
00144 {
00145     mic2latin(mic, p, len, LC_ISO8859_1, PG_LATIN1);
00146 }
00147 
00148 static void
00149 latin32mic(const unsigned char *l, unsigned char *p, int len)
00150 {
00151     latin2mic(l, p, len, LC_ISO8859_3, PG_LATIN3);
00152 }
00153 
00154 static void
00155 mic2latin3(const unsigned char *mic, unsigned char *p, int len)
00156 {
00157     mic2latin(mic, p, len, LC_ISO8859_3, PG_LATIN3);
00158 }
00159 
00160 static void
00161 latin42mic(const unsigned char *l, unsigned char *p, int len)
00162 {
00163     latin2mic(l, p, len, LC_ISO8859_4, PG_LATIN4);
00164 }
00165 
00166 static void
00167 mic2latin4(const unsigned char *mic, unsigned char *p, int len)
00168 {
00169     mic2latin(mic, p, len, LC_ISO8859_4, PG_LATIN4);
00170 }