cleaned up debug output

This commit is contained in:
Josh 2010-04-01 17:08:45 -04:00
parent 920478dfa4
commit 68b36d0310
2 changed files with 8 additions and 38 deletions

View File

@ -44,11 +44,5 @@ int main(int argc, char * argv[])
return 1;
}
cout << "Size: " << ucs_str->size() << endl;
for (int i = 0; i < ucs_str->size(); i++)
{
cout << dec << (*ucs_str)[i] << " (0x" << hex << (*ucs_str)[i] << "): '" << (char) ((*ucs_str)[i] & 0xFF) << "'" << endl;
}
return 0;
}

View File

@ -4,6 +4,7 @@
#include <iconv.h>
#include <stdio.h>
#include <errno.h>
#include <endian.h>
using namespace std;
refptr< vector<unichar_t> > deserialize(const char * encoding, istream & in)
@ -15,15 +16,14 @@ refptr< vector<unichar_t> > deserialize(const char * encoding, istream & in)
unichar_t * outbuf = new unichar_t[buf_size];
char * outbuf_ptr;
size_t chars_converted, inbytesleft = 0, outbytesleft;
const char * to_encoding;
const char * to_encoding
#if __BYTE_ORDER == __LITTLE_ENDIAN
= "UCS-4LE";
#else
= "UCS-4BE";
#endif
refptr< vector<unichar_t> > ucs = new vector<unichar_t>();
{
uint32_t endianness_test = 1u;
uint8_t * p = (uint8_t *) &endianness_test;
to_encoding = (*p == 1) ? "UCS-4LE" : "UCS-4BE";
}
iconv_t cd = iconv_open(/* to */ to_encoding, /* from */ encoding);
if (cd == (iconv_t) -1)
{
@ -34,45 +34,22 @@ refptr< vector<unichar_t> > deserialize(const char * encoding, istream & in)
outbuf_ptr = (char *) &outbuf[0];
outbytesleft = buf_size * sizeof(outbuf[0]);
iconv(cd, NULL, NULL, &outbuf_ptr, &outbytesleft);
cout << "initial outbytesleft: " << outbytesleft << endl;
for (;;)
{
in.read(inbuf_ptr, buf_size * sizeof(inbuf[0]) - inbytesleft);
num_read = in.gcount();
cout << "num_read: " << num_read << endl;
if (num_read <= 0)
break;
inbytesleft += num_read;
outbuf_ptr = (char *) &outbuf[0];
outbytesleft = buf_size * sizeof(outbuf[0]);
cout << "before inbytesleft: " << inbytesleft << ", outbytesleft: " << outbytesleft << endl;
// cout << "inbuf_ptr: " << inbuf_ptr << endl;
chars_converted = iconv(cd, &inbuf_ptr, &inbytesleft,
&outbuf_ptr, &outbytesleft);
if (chars_converted == (size_t) -1)
{
int err = errno;
perror("iconv() error");
switch (err)
{
case EINVAL:
cerr << "EINVAL" << endl;
break;
case EILSEQ:
cerr << "EILSEQ" << endl;
printf("inbuf: %p, inbuf_ptr: %p\n", inbuf, inbuf_ptr);
for (int i = 0; i < 6; i++)
printf("%02x ", inbuf_ptr[i]);
cout << endl;
break;
case E2BIG:
cerr << "E2BIG" << endl;
break;
perror("iconv()");
}
}
cout << "chars_converted: " << chars_converted << endl;
cout << "after inbytesleft: " << inbytesleft << ", outbytesleft: " << outbytesleft << endl;
if (inbytesleft > 0)
{
memmove(&inbuf[0], inbuf_ptr, inbytesleft);
@ -94,4 +71,3 @@ refptr< vector<unichar_t> > deserialize(const char * encoding, istream & in)
iconv_close(cd);
return ucs;
}