|
[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Expat and XML encoding
Hi!
I'm working on xml parser using expat and iconv libs. I'm trying to
achieve universal encoding handler, where map array is populated using
iconv function. Below is code snippet based on concept founded in
abiword source. Is it correct way to do encoding from for ex.
windows-1250 to utf-8? (asking 'cos text encoded in this way is not
correct utf-8)
Thanks in advance.
Best regards,
Tomasz Geisel.
--------------------------------
int encHandler(void *encodingHandlerData, const XML_Char
*name, XML_Encoding *info)
{
needConversion=true;
convDescriptor = iconv_open("UTF-8",name);
if (convDescriptor==(iconv_t)(-1))
return 0;
info->convert = NULL;
info->release = NULL;
char ibuf[1],obuf[2];
for(int i=0;i<256;++i)
{
size_t ibuflen = 1, obuflen=2;
const char* iptr = ibuf;
char* optr = obuf;
ibuf[0] = static_cast<unsigned char>(i);
size_t donecnt = iconv(convDescriptor,&iptr,&ibuflen,&optr,&obuflen);
if (donecnt!=(size_t)-1 && ibuflen==0)
{
unsigned short uval;
unsigned short b0 = static_cast<unsigned char>(obuf[0]);
unsigned short b1 = static_cast<unsigned char>(obuf[1]);
uval = b0 | (b1<<8);
info->map[i] = static_cast<unsigned int>(uval);
}
else
info->map[i] = -1;
}
iconv_close(convDescriptor);
return 1;
}
--------------------------------
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|
|||||||||

Cart








