Exemplo n.º 1
0
		/// ------------------------------------------------------------------------------------
		/// <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);
			}
		}