44 #include <freetds/tds.h>
45 #include <freetds/bytes.h>
46 #include <freetds/iconv.h>
47 #include <freetds/bool.h>
96 #define MASK(n) ((0xffffffffu << (n)) & 0xffffffffu)
99 if ((c &
MASK(7)) == 0) {
102 *
buf = (
unsigned char) c;
108 if ((c &
MASK(11)) == 0)
111 if ((c &
MASK(16)) == 0)
114 if ((c &
MASK(21)) == 0)
117 if ((c &
MASK(26)) == 0)
120 if ((c &
MASK(31)) != 0)
129 *--
buf = 0x80 | (c & 0x3f);
132 *--
buf = (0xff00u >> o_len) | c;
180 if ((c & 0xfc00) == 0xd800) {
184 if ((c2 & 0xfc00) == 0xdc00) {
185 *
out = (c << 10) + c2 - ((0xd800 << 10) + 0xdc00 - 0x10000);
219 if ((c & 0xfc00) == 0xd800) {
223 if ((c2 & 0xfc00) == 0xdc00) {
224 *
out = (c << 10) + c2 - ((0xd800 << 10) + 0xdc00 - 0x10000);
264 buf[0] = (
unsigned char) c;
284 buf[0] = (
unsigned char) c;
291 if (*p >= 0x80 && *p < 0xa0)
304 if (c >= 0x100 || ((c&~0x1fu) == 0x80 &&
cp1252_0080_00a0[c - 0x80] != c - 0x80)) {
306 #define CP1252(i,o) case o: c = i; break;
349 const char *enc_name;
350 unsigned char encodings[2];
352 static bool first_time =
true;
361 for (
i=0;
i < 2; ++
i) {
362 unsigned char encoding;
364 if (
strcmp(enc_name,
"ISO-8859-1") == 0)
366 else if (
strcmp(enc_name,
"US-ASCII") == 0)
368 else if (
strcmp(enc_name,
"UCS-2LE") == 0 ||
strcmp(enc_name,
"UTF-16LE") == 0)
370 else if (
strcmp(enc_name,
"UCS-2BE") == 0 ||
strcmp(enc_name,
"UTF-16BE") == 0)
372 else if (
strcmp(enc_name,
"UCS-4LE") == 0)
374 else if (
strcmp(enc_name,
"UCS-4BE") == 0)
376 else if (
strcmp(enc_name,
"UTF-8") == 0)
378 else if (
strcmp(enc_name,
"CP1252") == 0)
384 encodings[
i] = encoding;
389 fromto = (encodings[0] << 4) | (encodings[1] & 0x0F);
392 if (encodings[0] == encodings[1]) {
408 const unsigned char *ib;
414 #define CD ((int) (TDS_INTPTR) cd)
431 ib = (
const unsigned char*) *
inbuf;
432 ob = (
unsigned char*) *
outbuf;
435 size_t copybytes = (il < ol)? il : ol;
437 memcpy(ob, ib, copybytes);
442 }
else if (
CD & ~0xff) {
443 local_errno = EINVAL;
450 int readed = get_func(ib, il, &out_c), written;
454 local_errno = -readed;
458 written = put_func(ob, ol, out_c);
461 local_errno = -written;
474 *
inbuf = (
const char*) ib;
477 if (il && !local_errno)
static uint32_t decode_utf8(uint32_t *state, uint32_t *codep, uint32_t byte)
std::ofstream out("events_result.xml")
main entry point for tests
#define TDS_GET_UA4LE(ptr)
#define TDS_PUT_UA2LE(ptr, val)
#define TDS_GET_UA4BE(ptr)
#define TDS_PUT_UA2BE(ptr, val)
#define TDS_GET_UA2BE(ptr)
#define TDS_GET_UA2LE(ptr)
#define TDS_PUT_UA4BE(ptr, val)
#define TDS_PUT_UA4LE(ptr, val)
#define TDS_EXTRA_CHECK(stmt)
tds_sysdep_intptr_type TDS_INTPTR
static int put_ascii(unsigned char *buf, size_t buf_len, ICONV_CHAR c)
static int get_iso1(const unsigned char *p, size_t len, ICONV_CHAR *out)
static int get_utf8(const unsigned char *p, size_t len, ICONV_CHAR *out)
static int put_utf8(unsigned char *buf, size_t buf_len, ICONV_CHAR c)
static int get_utf16be(const unsigned char *p, size_t len, ICONV_CHAR *out)
static int get_err(const unsigned char *p, size_t len, ICONV_CHAR *out)
static int put_err(unsigned char *buf, size_t buf_len, ICONV_CHAR c)
static int get_ascii(const unsigned char *p, size_t len, ICONV_CHAR *out)
static int get_ucs4be(const unsigned char *p, size_t len, ICONV_CHAR *out)
static int get_utf16le(const unsigned char *p, size_t len, ICONV_CHAR *out)
static int put_ucs4le(unsigned char *buf, size_t buf_len, ICONV_CHAR c)
static int put_ucs4be(unsigned char *buf, size_t buf_len, ICONV_CHAR c)
static int put_iso1(unsigned char *buf, size_t buf_len, ICONV_CHAR c)
static int put_utf16be(unsigned char *buf, size_t buf_len, ICONV_CHAR c)
static int get_ucs4le(const unsigned char *p, size_t len, ICONV_CHAR *out)
static int put_utf16le(unsigned char *buf, size_t buf_len, ICONV_CHAR c)
static int get_cp1252(const unsigned char *p, size_t len, ICONV_CHAR *out)
static int put_cp1252(unsigned char *buf, size_t buf_len, ICONV_CHAR c)
static const iconv_get_t iconv_gets[16]
size_t tds_sys_iconv(iconv_t cd, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft)
static const iconv_put_t iconv_puts[16]
iconv_t tds_sys_iconv_open(const char *tocode, const char *fromcode)
Inputs are FreeTDS canonical names, no other.
int(* iconv_put_t)(unsigned char *buf, size_t buf_len, ICONV_CHAR c)
int tds_sys_iconv_close(iconv_t cd)
int(* iconv_get_t)(const unsigned char *p, size_t len, ICONV_CHAR *out)
unsigned int
A callback function used to compare two keys in a database.
static const uint16_t cp1252_0080_00a0[]
int strcmp(const char *str1, const char *str2)
static SLJIT_INLINE sljit_ins l(sljit_gpr r, sljit_s32 d, sljit_gpr x, sljit_gpr b)
uchar outbuf[(1000000+1000000)]