[Development] QUtf8String{, View}

Arnaud Clère arnaud.clere at moulinarso.fr
Sat May 16 17:52:19 CEST 2020


Hi all,

As a user, I am happy with simplifications regarding string handling and I
think the choice of utf16 for QString makes sense for most code except for
file/networking code.

I was once concerned about not being able to distinguish between QByteArray
containing utf8 text and QByteArray containing other data. But now, I am
using the following pattern to distinguish between both in the *very rare
places* where I need to have a different overload for each, or want to
provide a separate type with strong guarantees about a QByteArray content:

struct Utf8 { QByteArray utf8; }

This pattern obviously works for "tagging" any kind of data. See
https://www.fluentcpp.com/2018/04/06/strong-types-by-struct/ for a
presentation of this pattern.

Regarding the relevance of a QUtf8String, I feel like it would not be so
useful unless it allows to view its content as QChar instead of char (or
char8_t) since handling multibyte characters is so error prone. At least a
QChar handles most unicode characters as single entities...

Cheers,
Arnaud
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20200516/02443d7a/attachment.html>


More information about the Development mailing list