MCPcopy Create free account
hub / github.com/KDE/kdiff3 / preprocess

Method preprocess

src/SourceData.cpp:568–722  ·  view source on GitHub ↗

Prepare the linedata vector for every input line.*/

Source from the content-addressed store, hash-verified

566
567/** Prepare the linedata vector for every input line.*/
568bool 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 }

Callers 1

readAndPreprocessMethod · 0.80

Calls 14

LineDataClass · 0.85
readCharMethod · 0.80
appendMethod · 0.80
push_backMethod · 0.80
peekCharMethod · 0.80
processLineMethod · 0.80
getMethod · 0.45
setEncodingMethod · 0.45
hasBOMMethod · 0.45
clearMethod · 0.45
removeCommentMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected