[Development] Qt6: Adding UTF-8 storage support to QString

Jason H jhihn at gmx.com
Tue Jan 22 15:49:51 CET 2019



> Sent: Monday, January 21, 2019 at 9:51 AM
> From: "Arnaud Clère" <arnaud.clere at minmaxmedical.com>
> To: "Allan Sandfeld Jensen" <kde at carewolf.com>, "development at qt-project.org" <development at qt-project.org>
> Subject: Re: [Development] Qt6: Adding UTF-8 storage support to QString
>
> > -----Original Message-----
> > From: Allan Sandfeld Jensen <kde at carewolf.com> 
> >
> > On Dienstag, 15. Januar 2019 19:43:57 CET Cristian Adam wrote:
> > > Any chance of having UTF-8 storage support for QString?
> > > 
> > Use QByteArray when you can.
> 
> I think a QUtf8String class derived from QByteArray would help a lot making this happen in the real world!
> 1. It would be found more easily by users in need of a utf8 encoded dynamic string
> 2. It would allow making the encoding explicit (QString or QUtf8String or QLatin1String) in newer Qt APIs or user-defined ones, and even totally safe if disabling const char * casts is possible
> 3. It would allow adding QString-like APIs (like setNum(), simplified(), etc.) over the time without cluttering QByteArray
> 
> Moreover, I have a specific use-case where QByteArray args are used as binary data (say CBOR) and a specific Utf8String is useful to handle utf8 encoded args without always encoding/decoding to utf16.
> I might not be the only one...


Feel free to burn this suggestion with fire, but what about:

typedef QSymbolSequence<QLatin1Char> QLatin1String;
typedef QSymbolSequence<QRawChar> QByteArray;
typedef QSymbolSequence<QUtf8Char> QByteArray;
typedef QSymbolSequence<QUtf16Char> QString;

So they can have the same API? It really seems to me that the issue is storage, not that they need a different API to operate on the storage. 





More information about the Development mailing list