updating and debugging deserialize()
This commit is contained in:
parent
51c870b314
commit
a2acb832dd
@ -38,5 +38,11 @@ int main(int argc, char * argv[])
|
||||
return 1;
|
||||
}
|
||||
|
||||
cout << "Size: " << ucs_str->size() << endl;
|
||||
for (int i = 0; i < ucs_str->size(); i++)
|
||||
{
|
||||
cout << (*ucs_str)[i] << ": '" << (char) (*ucs_str)[i] << "'" << endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
16
serialize.cc
16
serialize.cc
@ -11,7 +11,7 @@ refptr< vector<unichar_t> > deserialize(const char * encoding, istream & in)
|
||||
char * inbuf_ptr = (char *) &inbuf[0];
|
||||
unichar_t outbuf[buf_size];
|
||||
char * outbuf_ptr;
|
||||
size_t bytes_converted, inbytesleft = 0, outbytesleft;
|
||||
size_t bytes_converted, inbytes = 0, outbytes;
|
||||
refptr< vector<unichar_t> > ucs = new vector<unichar_t>();
|
||||
|
||||
iconv_t cd = iconv_open(encoding, "UTF-32");
|
||||
@ -23,19 +23,19 @@ refptr< vector<unichar_t> > deserialize(const char * encoding, istream & in)
|
||||
|
||||
for (;;)
|
||||
{
|
||||
in.read(&inbuf[0], sizeof(inbuf) - inbytesleft);
|
||||
in.read(inbuf_ptr, sizeof(inbuf) - inbytes);
|
||||
num_read = in.gcount();
|
||||
if (num_read <= 0)
|
||||
break;
|
||||
outbuf_ptr = (char *) &outbuf[0];
|
||||
outbytesleft = sizeof(outbuf);
|
||||
bytes_converted = iconv(cd, &inbuf_ptr, &inbytesleft,
|
||||
&outbuf_ptr, &outbytesleft);
|
||||
if (inbytesleft > 0)
|
||||
outbytes = sizeof(outbuf);
|
||||
bytes_converted = iconv(cd, &inbuf_ptr, &inbytes,
|
||||
&outbuf_ptr, &outbytes);
|
||||
if (inbytes > 0)
|
||||
{
|
||||
memmove(&inbuf[0], inbuf_ptr, inbytesleft);
|
||||
inbuf_ptr = (char *) &inbuf[0];
|
||||
memmove(&inbuf[0], inbuf_ptr, inbytes);
|
||||
}
|
||||
inbuf_ptr = ((char *) &inbuf[0]) + inbytes;
|
||||
for (int i = 0; i < (bytes_converted / sizeof(outbuf[0])); i++)
|
||||
{
|
||||
ucs->push_back(outbuf[i]);
|
||||
|
Loading…
x
Reference in New Issue
Block a user