PostgreSQL Source Code  git master
utf8_and_win.c File Reference
#include "postgres.h"
#include "fmgr.h"
#include "mb/pg_wchar.h"
#include "../../Unicode/utf8_to_win1250.map"
#include "../../Unicode/utf8_to_win1251.map"
#include "../../Unicode/utf8_to_win1252.map"
#include "../../Unicode/utf8_to_win1253.map"
#include "../../Unicode/utf8_to_win1254.map"
#include "../../Unicode/utf8_to_win1255.map"
#include "../../Unicode/utf8_to_win1256.map"
#include "../../Unicode/utf8_to_win1257.map"
#include "../../Unicode/utf8_to_win1258.map"
#include "../../Unicode/utf8_to_win866.map"
#include "../../Unicode/utf8_to_win874.map"
#include "../../Unicode/win1250_to_utf8.map"
#include "../../Unicode/win1251_to_utf8.map"
#include "../../Unicode/win1252_to_utf8.map"
#include "../../Unicode/win1253_to_utf8.map"
#include "../../Unicode/win1254_to_utf8.map"
#include "../../Unicode/win1255_to_utf8.map"
#include "../../Unicode/win1256_to_utf8.map"
#include "../../Unicode/win1257_to_utf8.map"
#include "../../Unicode/win866_to_utf8.map"
#include "../../Unicode/win874_to_utf8.map"
#include "../../Unicode/win1258_to_utf8.map"
Include dependency graph for utf8_and_win.c:

Go to the source code of this file.

Data Structures

struct  pg_conv_map
 

Functions

 PG_FUNCTION_INFO_V1 (win_to_utf8)
 
 PG_FUNCTION_INFO_V1 (utf8_to_win)
 
Datum win_to_utf8 (PG_FUNCTION_ARGS)
 
Datum utf8_to_win (PG_FUNCTION_ARGS)
 

Variables

 PG_MODULE_MAGIC
 
static const pg_conv_map maps []
 

Function Documentation

◆ PG_FUNCTION_INFO_V1() [1/2]

PG_FUNCTION_INFO_V1 ( win_to_utf8  )

◆ PG_FUNCTION_INFO_V1() [2/2]

PG_FUNCTION_INFO_V1 ( utf8_to_win  )

◆ utf8_to_win()

Datum utf8_to_win ( PG_FUNCTION_ARGS  )

Definition at line 117 of file utf8_and_win.c.

References CHECK_ENCODING_CONVERSION_ARGS, generate_unaccent_rules::dest, encoding, ereport, errcode(), errmsg(), ERROR, i, lengthof, PG_GETARG_BOOL, PG_GETARG_CSTRING, PG_GETARG_INT32, PG_RETURN_INT32, PG_UTF8, and UtfToLocal().

118 {
119  int encoding = PG_GETARG_INT32(1);
120  unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
121  unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
122  int len = PG_GETARG_INT32(4);
123  bool noError = PG_GETARG_BOOL(5);
124  int i;
125 
127 
128  for (i = 0; i < lengthof(maps); i++)
129  {
130  if (encoding == maps[i].encoding)
131  {
132  int converted;
133 
134  converted = UtfToLocal(src, len, dest,
135  maps[i].map2,
136  NULL, 0,
137  NULL,
138  encoding,
139  noError);
140  PG_RETURN_INT32(converted);
141  }
142  }
143 
144  ereport(ERROR,
145  (errcode(ERRCODE_INTERNAL_ERROR),
146  errmsg("unexpected encoding ID %d for WIN character sets",
147  encoding)));
148 
149  PG_RETURN_INT32(0);
150 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
#define PG_RETURN_INT32(x)
Definition: fmgr.h:354
int UtfToLocal(const unsigned char *utf, int len, unsigned char *iso, const pg_mb_radix_tree *map, const pg_utf_to_local_combined *cmap, int cmapsize, utf_local_conversion_func conv_func, int encoding, bool noError)
Definition: conv.c:507
int errcode(int sqlerrcode)
Definition: elog.c:698
#define PG_GETARG_BOOL(n)
Definition: fmgr.h:274
#define lengthof(array)
Definition: c.h:734
#define ERROR
Definition: elog.h:46
static const pg_conv_map maps[]
Definition: utf8_and_win.c:66
#define ereport(elevel,...)
Definition: elog.h:157
#define CHECK_ENCODING_CONVERSION_ARGS(srcencoding, destencoding)
Definition: pg_wchar.h:527
int32 encoding
Definition: pg_database.h:41
int errmsg(const char *fmt,...)
Definition: elog.c:909
int i
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:277

◆ win_to_utf8()

Datum win_to_utf8 ( PG_FUNCTION_ARGS  )

Definition at line 81 of file utf8_and_win.c.

References CHECK_ENCODING_CONVERSION_ARGS, generate_unaccent_rules::dest, encoding, ereport, errcode(), errmsg(), ERROR, i, lengthof, LocalToUtf(), PG_GETARG_BOOL, PG_GETARG_CSTRING, PG_GETARG_INT32, PG_RETURN_INT32, and PG_UTF8.

82 {
83  int encoding = PG_GETARG_INT32(0);
84  unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
85  unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
86  int len = PG_GETARG_INT32(4);
87  bool noError = PG_GETARG_BOOL(5);
88  int i;
89 
91 
92  for (i = 0; i < lengthof(maps); i++)
93  {
94  if (encoding == maps[i].encoding)
95  {
96  int converted;
97 
98  converted = LocalToUtf(src, len, dest,
99  maps[i].map1,
100  NULL, 0,
101  NULL,
102  encoding,
103  noError);
104  PG_RETURN_INT32(converted);
105  }
106  }
107 
108  ereport(ERROR,
109  (errcode(ERRCODE_INTERNAL_ERROR),
110  errmsg("unexpected encoding ID %d for WIN character sets",
111  encoding)));
112 
113  PG_RETURN_INT32(0);
114 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
#define PG_RETURN_INT32(x)
Definition: fmgr.h:354
int errcode(int sqlerrcode)
Definition: elog.c:698
#define PG_GETARG_BOOL(n)
Definition: fmgr.h:274
#define lengthof(array)
Definition: c.h:734
#define ERROR
Definition: elog.h:46
static const pg_conv_map maps[]
Definition: utf8_and_win.c:66
#define ereport(elevel,...)
Definition: elog.h:157
#define CHECK_ENCODING_CONVERSION_ARGS(srcencoding, destencoding)
Definition: pg_wchar.h:527
int32 encoding
Definition: pg_database.h:41
int errmsg(const char *fmt,...)
Definition: elog.c:909
int i
int LocalToUtf(const unsigned char *iso, int len, unsigned char *utf, const pg_mb_radix_tree *map, const pg_local_to_utf_combined *cmap, int cmapsize, utf_local_conversion_func conv_func, int encoding, bool noError)
Definition: conv.c:717
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:277

Variable Documentation

◆ maps

const pg_conv_map maps[]
static
Initial value:
= {
{PG_WIN866, &win866_to_unicode_tree, &win866_from_unicode_tree},
{PG_WIN874, &win874_to_unicode_tree, &win874_from_unicode_tree},
{PG_WIN1250, &win1250_to_unicode_tree, &win1250_from_unicode_tree},
{PG_WIN1251, &win1251_to_unicode_tree, &win1251_from_unicode_tree},
{PG_WIN1252, &win1252_to_unicode_tree, &win1252_from_unicode_tree},
{PG_WIN1253, &win1253_to_unicode_tree, &win1253_from_unicode_tree},
{PG_WIN1254, &win1254_to_unicode_tree, &win1254_from_unicode_tree},
{PG_WIN1255, &win1255_to_unicode_tree, &win1255_from_unicode_tree},
{PG_WIN1256, &win1256_to_unicode_tree, &win1256_from_unicode_tree},
{PG_WIN1257, &win1257_to_unicode_tree, &win1257_from_unicode_tree},
{PG_WIN1258, &win1258_to_unicode_tree, &win1258_from_unicode_tree},
}

Definition at line 66 of file utf8_and_win.c.

◆ PG_MODULE_MAGIC

PG_MODULE_MAGIC

Definition at line 40 of file utf8_and_win.c.