[Development] QUtf8String{, View}
Thiago Macieira
thiago.macieira at intel.com
Fri May 15 20:31:54 CEST 2020
On sexta-feira, 15 de maio de 2020 10:52:49 PDT Matthew Woehlke wrote:
> > Like that, it's just "array of bytes of an arbitrary encoding (or none)".
> > There's still a reason to have QByteArray and it'll need to exist in
> > networking and file I/O code. That means the string classes, if any, need
> > to be convertible to QByteArray anyway.
>
> I think we can learn from Python 3 here... QByteArray should go the way
> of QStringList, i.e. yes, it *should* be a QVector<byte>. Like
> QVector<QString>, it might (should) have additional methods, such as
> explicit conversion to/from QString (a la Python's encode/decode), but
> it should *not* have string-like manipulation (e.g. toUpper).
Those are all Qt 7 work. We can deprecate those methods in Qt 6, but not
remove them in 6.0.
Python's bstr still behaves string-like and has methods like
QByteArray::indexOf(const char *). QVector has no such methods.
But since we do have QListSpecialMethods, we can add inject them into QVector
too.
> >> So, assuming the premise that QByteArray should not be string-ish
> >> anymore, what do we want to have as the result type of QString::toUtf8()
> >> and QString::toLatin1()? Do we really want mere bytes?
>
> Yes. Maybe. Again, this is how Python 3 works.
>
> It might make sense to have a QUtf8String class, but that should be
> distinct from, and not implicitly constructible from, QByteArray a.k.a.
> QVector<byte>. (Implicit conversion *to* QByteArray might be okay.)
>
> (BTW, is 'byte' QByte or std::byte? Can we possibly achieve the latter?)
There's no QByte and we shouldn't have that type.
std::byte is an enum around the actual byte type (unsigned char) and char is
also a byte.
--
Thiago Macieira - thiago.macieira (AT) intel.com
Software Architect - Intel System Software Products
More information about the Development
mailing list