Add support to std::u8string

11 views
Skip to first unread message

Andrey Moura

unread,
May 25, 2024, 10:47:26 AMMay 25
to wx-dev
In my application I have to call str.ToStdString() and then copy the characters to a std::u8string cause there's no conversion from std::string to std::u8string, then expending time on a non needed copy. My idea is to implement str.ToStdU8String() which does exactly the same as ToStdString(), but returns the result in a std::u8string. Also, a wxString::operator=(u8string) will be needed. Obviously, I will check for support to std::u8string.

I will implement on my local copy cause I really need it. If you think that's a good idea, please let me know to create PR on GitHub.

Vadim Zeitlin

unread,
May 25, 2024, 10:58:39 AMMay 25
to wx-...@googlegroups.com
On Sat, 25 May 2024 07:46:02 -0700 (PDT) Andrey Moura wrote:

AM> In my application I have to call str.ToStdString() and then copy the
AM> characters to a std::u8string cause there's no conversion from std::string
AM> to std::u8string, then expending time on a non needed copy.

IMNSHO std::u8string was a mistake exactly because it doesn't provide any
conversion -- other than by copying its contents -- to std::string. So
personally I just don't use it and always std::string directly with the
understanding that it always contains UTF-8 data.

AM> My idea is to implement str.ToStdU8String() which does exactly the same
AM> as ToStdString(), but returns the result in a std::u8string. Also, a
AM> wxString::operator=(u8string) will be needed. Obviously, I will check
AM> for support to std::u8string.
AM>
AM> I will implement on my local copy cause I really need it. If you think
AM> that's a good idea, please let me know to create PR on GitHub.

But if people really want to use std::u8string, why not, it shouldn't cost
us much to have it, so if you're motivated to do it, please go ahead.

However my advice would be to just avoid std::u8string (and char8_t).

Regards,
VZ
Reply all
Reply to author
Forward
0 new messages