/// ------------------------------------------------------------------------------------ /// <summary> /// Extracts the missing or added empty paras from a ScrVerse cluster. This method does /// not attempt to find matching empty paragraphs. /// </summary> /// <param name="cluster">The cluster which should be an AddedToCurrent or /// MissingInCurrent cluster.</param> /// ------------------------------------------------------------------------------------ private void ExtractMissingAddedEmptyParasFromScrVerseCluster(Cluster cluster) { Debug.Assert(cluster.clusterType == ClusterType.AddedToCurrent || cluster.clusterType == ClusterType.OrphansInCurrent || cluster.clusterType == ClusterType.MissingInCurrent || cluster.clusterType == ClusterType.OrphansInRevision); bool fIsCurrent = Cluster.CurrentIsSource(cluster.clusterType); // Extract missing/added items from beginning of cluster. int removedFromStart = ExtractMissingAddedItems(cluster, 0, cluster.Items(fIsCurrent), fIsCurrent, true); // Extract missing/added items from end of cluster. ExtractMissingAddedItems(cluster, cluster.Items(fIsCurrent) - 1, removedFromStart, fIsCurrent, false); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Extracts the empty leading or trailing paragraphs from a ScrVerse cluster. /// </summary> /// <param name="cluster">The cluster.</param> /// ------------------------------------------------------------------------------------ private void ExtractStanzaBreaksFromScrVerseCluster(Cluster cluster) { // Forward Scan // Start comparing at the beginning of cluster until we no longer find empty paragraphs // in both the current AND revision. int iMatchingEmptyParaFwd = -1; // the last index of matching empty paragraphs on the forward scan for (int iClstrItem = 0; iClstrItem < cluster.itemsCurr.Count; iClstrItem++) { if (iClstrItem >= cluster.itemsRev.Count) break; //no more Rev items to compare to if (cluster.itemsCurr[iClstrItem].isStanzaBreak && cluster.itemsRev[iClstrItem].isStanzaBreak) { ExtractMatchedItemsCluster(cluster, iClstrItem, iClstrItem, true); iMatchingEmptyParaFwd = iClstrItem; } else break; // finished with forward scan (found content paras) } // Need to determine if either side has non-matching stanza breaks before content paras. if (cluster.IsStanzaBreak(iMatchingEmptyParaFwd + 1, true)) { // Added empty paragraphs before current side. Move into added cluster(s) int endIndex = cluster.Items(true); ExtractMissingAddedItems(cluster, iMatchingEmptyParaFwd + 1, endIndex, true, true); } else if (cluster.IsStanzaBreak(iMatchingEmptyParaFwd + 1, false)) { // Added empty paragraphs before revision side. Move into missing cluster(s) int endIndex = cluster.Items(false); ExtractMissingAddedItems(cluster, iMatchingEmptyParaFwd + 1, endIndex, false, true); } // Backward Scan // Start comparing at the end of cluster until we no longer find empty paragraphs // in both the current AND revision. int cCorrelatedBkwrd = 0; for (int iClstrItemCurr = cluster.itemsCurr.Count - 1, iClstrItemRev = cluster.itemsRev.Count - 1; iClstrItemCurr > 0 && iClstrItemRev > 0; iClstrItemCurr--, iClstrItemRev--) { if (iClstrItemCurr <= iMatchingEmptyParaFwd) break; //we've reached the last Curr ScrVerse that was matched on the forward scan if (iClstrItemRev <= iMatchingEmptyParaFwd) break; //we've reached the last Rev ScrVerse that was correlated on the forward scan if (cluster.itemsCurr[iClstrItemCurr].isStanzaBreak && cluster.itemsRev[iClstrItemRev].isStanzaBreak) { ExtractMatchedItemsCluster(cluster, iClstrItemCurr, iClstrItemRev, false); cCorrelatedBkwrd++; } } // Need to determine if either side has non-matching empty paragraphs after content paras. int iStartScanCurr = cluster.Items(true) - cCorrelatedBkwrd - 1; int iStartScanRev = cluster.Items(false) - cCorrelatedBkwrd - 1; if (cluster.IsStanzaBreak(iStartScanCurr, true)) { // Added non-matching stanza breaks after current side. Move into new added cluster(s) ExtractMissingAddedItems(cluster, iStartScanCurr, iMatchingEmptyParaFwd + 1, true, false); } else if (cluster.IsStanzaBreak(iStartScanRev, false)) { // Added non-matching stanza breaks after revision side. Move into new missing cluster(s) ExtractMissingAddedItems(cluster, iStartScanRev, iMatchingEmptyParaFwd + 1, false, false); } }