CompactHistoryLine::CompactHistoryLine ( const TextLine& line, CompactHistoryBlockList& bList ) : blockList(bList), formatLength(0) { length=line.size(); if (line.size() > 0) { formatLength=1; int k=1; // count number of different formats in this text line Character c = line[0]; while ( k<length ) { if ( !(line[k].equalsFormat(c))) { formatLength++; // format change detected c=line[k]; } k++; } //kDebug() << "number of different formats in string: " << formatLength; formatArray = (CharacterFormat*) blockList.allocate(sizeof(CharacterFormat)*formatLength); Q_ASSERT (formatArray!=nullptr); text = (quint16*) blockList.allocate(sizeof(quint16)*line.size()); Q_ASSERT (text!=nullptr); length=line.size(); wrapped=false; // record formats and their positions in the format array c=line[0]; formatArray[0].setFormat ( c ); formatArray[0].startPos=0; // there's always at least 1 format (for the entire line, unless a change happens) k=1; // look for possible format changes int j=1; while ( k<length && j<formatLength ) { if (!(line[k].equalsFormat(c))) { c=line[k]; formatArray[j].setFormat(c); formatArray[j].startPos=k; //kDebug() << "format entry " << j << " at pos " << formatArray[j].startPos << " " << &(formatArray[j].startPos) ; j++; } k++; } // copy character values for ( int i=0; i<line.size(); i++ ) { text[i]=line[i].character; //kDebug() << "char " << i << " at mem " << &(text[i]); } } //kDebug() << "line created, length " << length << " at " << &(length); }
TextFileIterator& TextFileIterator::operator --() { if (0 < mColumnIndex) { mColumnIndex--; } else { if (0 < mLineIndex) { mLineIndex--; TextLine *beforeLine = mFile->mLines[mLineIndex]; mColumnIndex = beforeLine->size() - 1; } } return *this; }
TextFileIterator& TextFileIterator::operator ++() { TextLine *line = mFile->mLines[mLineIndex]; if (line->size() - 1 > mColumnIndex) { mColumnIndex++; } else { if (mFile->mLines.size() > mLineIndex) { bool needChangeLine = false; const char *lfBytes = line->getLineFeed(); int lfBytesLen = (int) sizeof(lfBytes) - 1; mLineFeedIndex++; if (mLineFeedIndex == lfBytesLen) { mLineFeedIndex = -1; needChangeLine = true; } if (needChangeLine) { mLineIndex++; mColumnIndex = 0; } } } return *this; }