Re: [libxml++] SIGABRT received during xmlpp::Document::write_to_string_formatted



On Mon, 2005-02-07 at 22:40 +0100, Cyril PICARD wrote:
> The Glib::convert seems ok. It effectively throws a Glib::ConvertError 
> exception, but you did not catch it in your test case.

Yeah I think I sent you a slightly older version.

> 
> According to the Glib::ustring documentation, I have to use 
> ustring::raw() with operator <<(). It effectively works fine.

I don't think that's what the documentation says. It depends what you
are doing. std:: streams such as std::cout can not handle utf8, and if
you don't use raw() then the utf8 will automatically be converted to
something that they can handle.

> I made some slight modifications of my program, and I do not have the 
> SIGABRT anymore. Now I've got an exception in Glib::ustring 
> Glib::ustring xmlpp::Document::do_write_to_string(
>      const Glib::ustring& encoding,
>      bool format)
> 
> In this function if I replace
> 	Glib::ustring result((char*)buffer, length);
> by
>        	Glib::ustring result((char*)buffer);
> 
> no more exception is raised...

Could you try this instead, please:

// Here we force the use of Glib::ustring::ustring( InputIterator begin,
InputIterator end )
// instead of Glib::ustring::ustring( const char*, size_type ) because
it
// expects the length of the string in characters, not in bytes.
Glib::ustring result( reinterpret_cast<const char *>(buffer),
reinterpret_cast<const char *>(buffer + length) );


> And in xmlencode.cpp I can then output my raw data by
> std::cerr << result_xml.raw() << std::endl;

> Is there a reason to use Glib::ustring result((char*)buffer, length) 
> instead of Glib::ustring result((char*)buffer) ?

We get the buffer from a function that also gives us the length, so it's
a good idea not to assume that the text is null-terminated.

-- 
Murray Cumming
murrayc murrayc com
www.murrayc.com
www.openismus.com





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]