/// ------------------------------------------------------------------------------------ /// <summary> /// Make a new cluster for missing/added. /// </summary> /// <param name="insertInOtherIndex">Index where added/missing cluster should be inserted in other.</param> /// <param name="iItem">The index of the item.</param> /// <param name="cluster">The cluster.</param> /// <param name="fIsCurrent">if set to <c>true</c> extract from the current side; /// <c>false</c> extract from the revision side.</param> /// ------------------------------------------------------------------------------------ private void AddMissingAddedCluster(int insertInOtherIndex, int iItem, Cluster cluster, bool fIsCurrent) { Cluster newCluster = new Cluster(); newCluster.clusterType = (fIsCurrent) ? ClusterType.AddedToCurrent : ClusterType.MissingInCurrent; newCluster.verseRefMin = cluster.verseRefMin; newCluster.verseRefMax = cluster.verseRefMax; newCluster.indexToInsertAtInOther = insertInOtherIndex; newCluster.ItemList(fIsCurrent).Add(cluster.Item(iItem, fIsCurrent)); m_clusterList.Add(newCluster); // Mark the item in the original complex cluster for later deletion if (fIsCurrent) cluster.itemsCurr[iItem] = null; else cluster.itemsRev[iItem] = null; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Extracts the missing or added items from a cluster. /// </summary> /// <param name="cluster">The cluster.</param> /// <param name="iFrom">Beginning limit for extracting items.</param> /// <param name="iTo">Ending limit for extracting items.</param> /// <param name="fIsCurrent">if set to <c>true</c> extract from the current side; /// <c>false</c> extract from the revision side.</param> /// <param name="fFwd">if <c>true</c> scanning forward; otherwise scan backward</param> /// <returns>number of extracted added or missing empty ScrVerses</returns> /// ------------------------------------------------------------------------------------ private int ExtractMissingAddedItems(Cluster cluster, int iFrom, int iTo, bool fIsCurrent, bool fFwd) { // Determine index to insert in other. int newIndexToInsertAtInOther; if (cluster.indexToInsertAtInOther != -1) newIndexToInsertAtInOther = cluster.indexToInsertAtInOther; else newIndexToInsertAtInOther = cluster.ItemList(fIsCurrent)[iFrom].indexInOwner; Debug.Assert(newIndexToInsertAtInOther != -1); int extracted = 0; if (fFwd) { // Scan forward from end of matching empty paras at beginning of cluster for (int iItem = iFrom; iItem < iTo; iItem++) { if (!cluster.Item(iItem, fIsCurrent).isStanzaBreak) break; AddMissingAddedCluster(newIndexToInsertAtInOther, iItem, cluster, fIsCurrent); extracted++; } } else { // Scan backward from end of matching empty paras at cluster end for (int iItem = iFrom; iItem > iTo; iItem--) { if (!cluster.Item(iItem, fIsCurrent).isStanzaBreak) break; // Since we are handling added/missing items at the end of the cluster, // we want to set the insertion point at the end of the other side. AddMissingAddedCluster(newIndexToInsertAtInOther, iItem, cluster, fIsCurrent); extracted++; } } return extracted; }