| 53 | }; |
| 54 | |
| 55 | inline qint32 readChar(QString& s) |
| 56 | { |
| 57 | char curData = '\0'; |
| 58 | qint32 len = 0; |
| 59 | QStringDecoder decoder = QStringDecoder(mEncoding, mGenerateBOM ? QStringConverter::Flag::WriteBom : QStringConverter::Flag::ConvertInitialBom); |
| 60 | assert(decoder.isValid()); |
| 61 | if(!decoder.isValid()) return 0; |
| 62 | |
| 63 | /* |
| 64 | As long as the encoding is incomplete QStringDecoder returns an empty string and waits for more data. |
| 65 | This loop proceeds one byte at a time until we hit the end of input, get an encoded char and encounter an error. |
| 66 | */ |
| 67 | do |
| 68 | { |
| 69 | len += readRawData(&curData, 1); |
| 70 | |
| 71 | s = decoder(QByteArray::fromRawData(&curData, sizeof(curData))); |
| 72 | } while(!decoder.hasError() && s.isEmpty() && !atEnd()); |
| 73 | |
| 74 | mError = decoder.hasError() || (s.isEmpty() && atEnd()); |
| 75 | if(mError) |
| 76 | { |
| 77 | s[0] = QChar::SpecialCharacter::ReplacementCharacter; |
| 78 | s[1] = QChar::SpecialCharacter::Null; |
| 79 | } |
| 80 | |
| 81 | return len; |
| 82 | } |
| 83 | |
| 84 | quint64 peekChar(QString &s) |
| 85 | { |
no test coverage detected