UTF-8 error in GtkTextView while decoding base64



Hi, I have been trying to figure this out for a few days now. All I am
trying to do is decode a base64 string and add it to a Gtk::TextView.
Below is the code:

    txtbuffer_ = Gtk::TextBuffer::create();
    txtview_.set_buffer(txtbuffer_);
    const Glib::ustring str = Glib::Base64::decode("YmJi3A==");
    txtbuffer_->set_text(str);

When I run the program I get the error:

    Gtk-CRITICAL **: gtk_text_buffer_emit_insert: assertion
'g_utf8_validate (text, len, NULL)' failed

This error only occurs with Unicode characters. When the text is ASCII
it all works fine.
I have tried three different base64 decoders, I tried using std::string
and Glib::ustring with all the different decoders. I also tried using
the function `Glib::locale_to_utf8()`, but that gives me the error
`terminate called after throwing an instance of 'Glib::ConvertError'`.
And I tried using `Glib::convert` with the same error.

I know that Gtk::TextView can display Unicode because if I set the text
to a string with Unicode it will display the text.
I read that Gtk::TextView displays text in UTF-8, so I think my problem
is that the decoded string is not coded in UTF-8, but I am not sure. So
my question is how can I get Gtk::TextView to display the decoded base64?

Thank you.



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