String Encoding

Added by lm at 2 months ago

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

"wat’ry"

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:

54,68,65,20,77,61,74,e2,80,99,72,79,20,77,6f,72,6c,64,73,20,61,72,65,20,61,6c,6c,20,48,69,73,20,6f,77,6e,2c,.

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 2 months ago

Hey,

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 2 months ago

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

Thank you.

(1-2/2)