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

Arnaud Clère arnaud.clere at minmaxmedical.com
Tue Jan 22 18:01:16 CET 2019


> ----Original Message-----
> From: Jason H <jhihn at gmx.com> 
>
> > From: "Arnaud Clère" <arnaud.clere at minmaxmedical.com>
> >
> > > -----Original Message-----
> > > From: Allan Sandfeld Jensen <kde at carewolf.com>
> > >
> > > Use QByteArray when you can.
> > 
> > I think a QUtf8String class derived from QByteArray would help a lot making this happen in the real world!
>
> 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. 

This is close to QStringView and it would be nice to be able to build one from QByteArray/QUtf8String to access utf8 characters as QChar on the fly. It would avoid most MBCS problems with utf8 strings. Unfortunately, I am afraid this is not possible for QStringView since it must know the number of remaining characters and utf8 requires to decode the whole string to know that.

My point was not as ambitious:
QByteArray is the official way to deal with utf8 strings but:
1. This discussion shows it is not as known as it should be and I argue the name does not help
2. Dealing with binary data and all kind of string encodings in a single class is error-prone

Hence my suggestion of adding a QUtf8String deriving from QByteArray...

I have no idea if it would be feasible though



More information about the Development mailing list