Пример #1
0
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>   <Diff analysis algoritms>   <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
/// Método que analiza os 2 ficheiros actualziando as estruturas auxiliares necessárias para fazer o output da diferença entre eles
void Diff::analyzeFiles() {
    findCorrespondentLines();

    for (size_t lineIndex = 0; lineIndex < originalFileLinesStatus.size(); ++lineIndex) {
        LCS lcs;
        string LCSFound;

        if (originalFileLinesStatus[lineIndex].getLinesStatus() == LINE_MODIFIED) {
            lcs = LCS(originalFileData[lineIndex], modifiedFileData[lineIndex]);
            LCSFound = lcs.findLCS();
        }

        if (originalFileLinesStatus[lineIndex].getLinesStatus() == LINE_MOVED_AND_MODIFIED) {
            lcs = LCS(originalFileData[lineIndex], modifiedFileData[originalFileMovedLinesIndexsInModifiedFile[lineIndex]]);
            LCSFound = lcs.findLCS();
        }

        if (LCSFound.empty())
            continue;

        //update aos infos dos chars da linha do ficheiro original
        size_t currentPosOnLCS = 0;
        vector <bool> lineCharsChangedOnOriginalFile(originalFileData[lineIndex].size(), true);
        for (size_t charIndex = 0; charIndex < originalFileData[lineIndex].size(); ++charIndex) {
            if (currentPosOnLCS < LCSFound.size()) {
                if (LCSFound[currentPosOnLCS] == originalFileData[lineIndex][charIndex]) {
                    lineCharsChangedOnOriginalFile[charIndex] = false;
                    ++currentPosOnLCS;
                }
            } else {
                break;
            }
        }

        originalFileLinesStatus[lineIndex].setLineCharsChangedOnOriginalFile(lineCharsChangedOnOriginalFile);



        //update aos infos dos chars da linha do ficheiro modificado
        currentPosOnLCS = 0;
        int indexOfOriginalLineOnModifiedFile = originalFileMovedLinesIndexsInModifiedFile[lineIndex];
        vector <bool> lineCharsChangedOnModifiedFile(modifiedFileData[indexOfOriginalLineOnModifiedFile].size(), true);
        for (size_t charIndex = 0; charIndex < modifiedFileData[indexOfOriginalLineOnModifiedFile].size(); ++charIndex) {
            if (currentPosOnLCS < LCSFound.size()) {
                if (LCSFound[currentPosOnLCS] == modifiedFileData[indexOfOriginalLineOnModifiedFile][charIndex]) {
                    lineCharsChangedOnModifiedFile[charIndex] = false;
                    ++currentPosOnLCS;
                }
            } else {
                break;
            }
        }

        originalFileLinesStatus[lineIndex].setLineCharsChangedOnModifiedFile(lineCharsChangedOnModifiedFile);


    }
}
Пример #2
0
int main()
{
	string A="1A2C3D4B56",B="B1D23CA45B6A";
	LCS f;
	cout<<f.findLCS(A,10,B,12);
	return 0;
}