From b359fd6c2a0b64ce3f4a942ec2ce9afd931b0933 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Sun, 15 Nov 2020 18:49:29 -0800 Subject: [PATCH] QStringConverter: add comments marking the BOM checks and emissions Because obscure cultural references never go out of style. https://twitter.com/steveklabnik/status/1327745325688365056?s=21 Change-Id: Idbe0d2174d4943d1865cfffd1647dd3a18af1801 Reviewed-by: Lars Knoll --- src/corelib/text/qstringconverter.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/corelib/text/qstringconverter.cpp b/src/corelib/text/qstringconverter.cpp index a0015c2c837..524bb4cc036 100644 --- a/src/corelib/text/qstringconverter.cpp +++ b/src/corelib/text/qstringconverter.cpp @@ -912,6 +912,7 @@ char *QUtf16::convertFromUnicode(char *out, QStringView in, QStringConverter::St endian = (QSysInfo::ByteOrder == QSysInfo::BigEndian) ? BigEndianness : LittleEndianness; if (writeBom) { + // set them up the BOM QChar bom(QChar::ByteOrderMark); if (endian == BigEndianness) qToBigEndian(bom.unicode(), out); @@ -974,6 +975,7 @@ QChar *QUtf16::convertToUnicode(QChar *out, QByteArrayView in, QStringConverter: state->internalState |= HeaderDone; QChar ch(buf, *chars++); if (endian == DetectEndianness) { + // someone set us up the BOM if (ch == QChar::ByteOrderSwapped) { endian = BigEndianness; } else if (ch == QChar::ByteOrderMark) { @@ -1043,6 +1045,7 @@ char *QUtf32::convertFromUnicode(char *out, QStringView in, QStringConverter::St endian = (QSysInfo::ByteOrder == QSysInfo::BigEndian) ? BigEndianness : LittleEndianness; if (writeBom) { + // set them up the BOM if (endian == BigEndianness) { out[0] = 0; out[1] = 0; @@ -1151,6 +1154,7 @@ QChar *QUtf32::convertToUnicode(QChar *out, QByteArrayView in, QStringConverter: while (num < 4) tuple[num++] = *chars++; if (endian == DetectEndianness) { + // someone set us up the BOM? if (tuple[0] == 0xff && tuple[1] == 0xfe && tuple[2] == 0 && tuple[3] == 0) { endian = LittleEndianness; } else if (tuple[0] == 0 && tuple[1] == 0 && tuple[2] == 0xfe && tuple[3] == 0xff) { @@ -1757,6 +1761,7 @@ std::optional QStringConverter::encodingForName(cons */ std::optional QStringConverter::encodingForData(QByteArrayView data, char16_t expectedFirstCharacter) { + // someone set us up the BOM? qsizetype arraySize = data.size(); if (arraySize > 3) { uint uc = qFromUnaligned(data.data());