1
/*-------------------------------------------------------------------------
5
* Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group
6
* Portions Copyright (c) 1994, Regents of the University of California
9
* src/backend/utils/mb/conversion_procs/utf8_and_ascii/utf8_and_ascii.c
11
*-------------------------------------------------------------------------
16
#include "mb/pg_wchar.h"
20
PG_FUNCTION_INFO_V1(ascii_to_utf8);
21
PG_FUNCTION_INFO_V1(utf8_to_ascii);
23
extern Datum ascii_to_utf8(PG_FUNCTION_ARGS);
24
extern Datum utf8_to_ascii(PG_FUNCTION_ARGS);
28
* INTEGER, -- source encoding id
29
* INTEGER, -- destination encoding id
30
* CSTRING, -- source string (null terminated C string)
31
* CSTRING, -- destination string (null terminated C string)
32
* INTEGER -- source string length
38
ascii_to_utf8(PG_FUNCTION_ARGS)
40
unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
41
unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
42
int len = PG_GETARG_INT32(4);
44
CHECK_ENCODING_CONVERSION_ARGS(PG_SQL_ASCII, PG_UTF8);
46
/* this looks wrong, but basically we're just rejecting high-bit-set */
47
pg_ascii2mic(src, dest, len);
53
utf8_to_ascii(PG_FUNCTION_ARGS)
55
unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
56
unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
57
int len = PG_GETARG_INT32(4);
59
CHECK_ENCODING_CONVERSION_ARGS(PG_UTF8, PG_SQL_ASCII);
61
/* this looks wrong, but basically we're just rejecting high-bit-set */
62
pg_mic2ascii(src, dest, len);