22 static bool qt_is_ascii(
const char *&ptr,
const char *end ) noexcept
24 while ( ptr + 4 <= end )
26 quint32 data = qFromUnaligned<quint32>( ptr );
27 if ( data &= 0x80808080U )
29 #if Q_BYTE_ORDER == Q_BIG_ENDIAN
30 uint idx = qCountLeadingZeroBits( data );
32 const uint idx = qCountTrailingZeroBits( data );
41 if ( quint8( *ptr ) & 0x80 )
63 const char *in = ba.constData();
64 const char *
const end = ba.constEnd();
65 if ( qt_is_ascii( in, end ) )
68 return QString::fromLatin1( ba, ba.size() );
71 QByteArray intermediate = ba;
72 intermediate.resize( ba.size() * 3 - ( in - ba.constData() ) );
73 uchar *out =
reinterpret_cast<uchar *
>( intermediate.data() + ( in - ba.constData() ) );
74 for ( ; in < end; ++in )
86 *out++ = uchar( *in );
90 return QString::fromLatin1( intermediate, out -
reinterpret_cast<uchar *
>( intermediate.data() ) );