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 <lars.knoll@qt.io>
This commit is contained in:
parent
af520c8ef3
commit
b359fd6c2a
@ -912,6 +912,7 @@ char *QUtf16::convertFromUnicode(char *out, QStringView in, QStringConverter::St
|
|||||||
endian = (QSysInfo::ByteOrder == QSysInfo::BigEndian) ? BigEndianness : LittleEndianness;
|
endian = (QSysInfo::ByteOrder == QSysInfo::BigEndian) ? BigEndianness : LittleEndianness;
|
||||||
|
|
||||||
if (writeBom) {
|
if (writeBom) {
|
||||||
|
// set them up the BOM
|
||||||
QChar bom(QChar::ByteOrderMark);
|
QChar bom(QChar::ByteOrderMark);
|
||||||
if (endian == BigEndianness)
|
if (endian == BigEndianness)
|
||||||
qToBigEndian(bom.unicode(), out);
|
qToBigEndian(bom.unicode(), out);
|
||||||
@ -974,6 +975,7 @@ QChar *QUtf16::convertToUnicode(QChar *out, QByteArrayView in, QStringConverter:
|
|||||||
state->internalState |= HeaderDone;
|
state->internalState |= HeaderDone;
|
||||||
QChar ch(buf, *chars++);
|
QChar ch(buf, *chars++);
|
||||||
if (endian == DetectEndianness) {
|
if (endian == DetectEndianness) {
|
||||||
|
// someone set us up the BOM
|
||||||
if (ch == QChar::ByteOrderSwapped) {
|
if (ch == QChar::ByteOrderSwapped) {
|
||||||
endian = BigEndianness;
|
endian = BigEndianness;
|
||||||
} else if (ch == QChar::ByteOrderMark) {
|
} 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;
|
endian = (QSysInfo::ByteOrder == QSysInfo::BigEndian) ? BigEndianness : LittleEndianness;
|
||||||
|
|
||||||
if (writeBom) {
|
if (writeBom) {
|
||||||
|
// set them up the BOM
|
||||||
if (endian == BigEndianness) {
|
if (endian == BigEndianness) {
|
||||||
out[0] = 0;
|
out[0] = 0;
|
||||||
out[1] = 0;
|
out[1] = 0;
|
||||||
@ -1151,6 +1154,7 @@ QChar *QUtf32::convertToUnicode(QChar *out, QByteArrayView in, QStringConverter:
|
|||||||
while (num < 4)
|
while (num < 4)
|
||||||
tuple[num++] = *chars++;
|
tuple[num++] = *chars++;
|
||||||
if (endian == DetectEndianness) {
|
if (endian == DetectEndianness) {
|
||||||
|
// someone set us up the BOM?
|
||||||
if (tuple[0] == 0xff && tuple[1] == 0xfe && tuple[2] == 0 && tuple[3] == 0) {
|
if (tuple[0] == 0xff && tuple[1] == 0xfe && tuple[2] == 0 && tuple[3] == 0) {
|
||||||
endian = LittleEndianness;
|
endian = LittleEndianness;
|
||||||
} else if (tuple[0] == 0 && tuple[1] == 0 && tuple[2] == 0xfe && tuple[3] == 0xff) {
|
} else if (tuple[0] == 0 && tuple[1] == 0 && tuple[2] == 0xfe && tuple[3] == 0xff) {
|
||||||
@ -1757,6 +1761,7 @@ std::optional<QStringConverter::Encoding> QStringConverter::encodingForName(cons
|
|||||||
*/
|
*/
|
||||||
std::optional<QStringConverter::Encoding> QStringConverter::encodingForData(QByteArrayView data, char16_t expectedFirstCharacter)
|
std::optional<QStringConverter::Encoding> QStringConverter::encodingForData(QByteArrayView data, char16_t expectedFirstCharacter)
|
||||||
{
|
{
|
||||||
|
// someone set us up the BOM?
|
||||||
qsizetype arraySize = data.size();
|
qsizetype arraySize = data.size();
|
||||||
if (arraySize > 3) {
|
if (arraySize > 3) {
|
||||||
uint uc = qFromUnaligned<uint>(data.data());
|
uint uc = qFromUnaligned<uint>(data.data());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user