String Encoding

Added by lm at 4 months ago

I am reading a string from a file, and it has the following characters in it:


That apostrophe is three bytes in unicode. I'm using archlinux. std::locale("").name() returns "en_US.UTF-8". When I use

Wt::WString send_str {Wt::WString::fromUTF8(line)};
new Wt::WText{line, this};

The output in the browser is wat???ry. There is an error in the console:

[2017-May-18 13:04:33.626370] 4766 [/sacred_harp FenQbOv8JSsJI0TL] [error] "WString: widen(): could not widen string: The wat’ry worlds are all His own,"

I wrote out all the bytes for that string, and I have:


Remembering that "20" is space, It looks like my code point is 0xe2, 0x80, 0x99 UTF-8.

I'm not sure what else to do to get this string to show up properly on the web page. I guess Wt re-encodes strings to match the locale requested by the browser, which should be fine, but obviously I'm missing something. Any help would be greatly appreciated. Thank you!

By the way, I tried to send this to the mailing list, but my message was returned.

Replies (2)

RE: String Encoding - Added by Koen Deforche 4 months ago


That should be fine were it not of this typo?

Wt::WString send_str {Wt::WString::fromUTF8(line)};
new Wt::WText{send_str, this};

RE: String Encoding - Added by lm at 4 months ago

Thou hast spoken. I bow and skooch backward out of the room.

Thank you.