in win_unicode.c [731:774]
int ucs2_to_ucs4(const SQLWCHAR *ucs2str, SQLLEN ilen, unsigned int *ucs4str, int bufcount)
{
int outlen = 0, i;
UCHAR *ucdt;
SQLWCHAR sqlwdt;
unsigned int dmy_uint;
UCHAR * const udt = (UCHAR *) &dmy_uint;
MYLOG(MIN_LOG_LEVEL, " ilen=" FORMAT_LEN " bufcount=%d\n", ilen, bufcount);
if (ilen < 0)
ilen = ucs2strlen(ucs2str);
udt[3] = 0; /* always */
for (i = 0; i < ilen && (sqlwdt = ucs2str[i]); i++)
{
ucdt = (UCHAR *)(ucs2str + i);
// printf("IN=%x\n", sqlwdt);
if ((ucdt[1] & SURROGATE_CHECK) != SURROG1_BYTE)
{
// printf("SURROG1=%2x\n", ucdt[1] & SURROG1_BYTE);
if (outlen < bufcount)
{
udt[0] = ucdt[0];
udt[1] = ucdt[1];
udt[2] = 0;
ucs4str[outlen] = *((unsigned int *)udt);
}
outlen++;
continue;
}
/* surrogate pair */
udt[0] = ucdt[2];
udt[1] = (ucdt[3] & 0x3) | ((ucdt[0] & 0x3f) << 2);
udt[2] = (((ucdt[0] & 0xc0) >> 6) | ((ucdt[1] & 0x3) << 2)) + 1;
// udt[3] = 0; needless
if (outlen < bufcount)
ucs4str[outlen] = *((unsigned int *)udt);
outlen++;
i++;
}
if (outlen < bufcount)
ucs4str[outlen] = 0;
return outlen;
}