Prepare the linedata vector for every input line.*/
| 566 | |
| 567 | /** Prepare the linedata vector for every input line.*/ |
| 568 | bool SourceData::FileData::preprocess(const QByteArray& encoding, bool removeComments) |
| 569 | { |
| 570 | if(m_pBuf == nullptr) |
| 571 | return true; |
| 572 | |
| 573 | QString line; |
| 574 | QString curChar, prevChar; |
| 575 | LineType lines = 0; |
| 576 | qsizetype lastOffset = 0; |
| 577 | std::unique_ptr<CommentParser> parser(new DefaultCommentParser()); |
| 578 | |
| 579 | // detect line end style |
| 580 | std::vector<e_LineEndStyle> vOrigDataLineEndStyle; |
| 581 | m_eLineEndStyle = eLineEndStyleUndefined; |
| 582 | |
| 583 | QByteArray pCodec = detectEncoding(m_pBuf.get(), mDataSize).value_or(encoding); |
| 584 | |
| 585 | if(mDataSize > limits<qint32>::max()) |
| 586 | { |
| 587 | reset(); |
| 588 | return false; |
| 589 | } |
| 590 | |
| 591 | try |
| 592 | { |
| 593 | const QByteArray ba = QByteArray::fromRawData(m_pBuf.get(), (qsizetype)(mDataSize)); |
| 594 | EncodedDataStream ds(ba); |
| 595 | |
| 596 | ds.setEncoding(encoding); |
| 597 | mHasBOM = ds.hasBOM(); |
| 598 | m_bIncompleteConversion = false; |
| 599 | m_unicodeBuf->clear(); |
| 600 | |
| 601 | assert(m_unicodeBuf->length() == 0); |
| 602 | |
| 603 | mHasEOLTermination = false; |
| 604 | while(!ds.atEnd()) |
| 605 | { |
| 606 | line.clear(); |
| 607 | if(lines >= limits<LineType>::max() - 5) |
| 608 | { |
| 609 | reset(); |
| 610 | return false; |
| 611 | } |
| 612 | |
| 613 | prevChar = curChar; |
| 614 | ds.readChar(curChar); |
| 615 | |
| 616 | qsizetype firstNonwhite = 0; |
| 617 | bool foundNonWhite = false; |
| 618 | |
| 619 | while(curChar != '\n' && curChar != '\r') |
| 620 | { |
| 621 | if(curChar[0].isNull() || curChar[0].isNonCharacter()) |
| 622 | { |
| 623 | m_v->clear(); |
| 624 | return true; |
| 625 | } |
no test coverage detected