Search code examples
gtkprintfvala

How to decode an escaped UTF-8 string?


I'm using Vala and GTK but I think someone may be able to help without either of these things being relevant. Using Vala I can access some C functions like printf and if necessary create bindings to anything else.

GTK's Entry widget escapes text and when the string is used internally it works fine. But if I try to put it into an output stream crème brûlée is escaped like cr\303\250me br\303\273l\303\251e.

Using printf, any of the GTK functions, or anything Vala supports, how can I unescape these characters?


Solution

  • Assuming you want to see the string as a list of Unicode codepoints, you can use string.get_next_char to iterate over the string one codepoint at a time. An example is in the reference.

    If you want graphemes, I do not know of a way to do this using GLib/Vala.