//该方法将不同行细分为:修改、删除、新增类型; private bool AddChanges( ArrayList report, int curDest, int nextDest, int curSource, int nextSource) { bool retval = false; int diffDest = nextDest - curDest;//下一个区域的索引减去当前区域索引(区域总共多少行?) int diffSource = nextSource - curSource; int minDiff = 0; if (diffDest > 0) { if (diffSource > 0) { minDiff = Math.Min(diffDest, diffSource); //curDest---新版本文件中区域块第一行的索引 //curSource --- 老版本文件中区域块第一行索引 //minDiff ---区域块中行数目 report.Add(DiffResultSpan.CreateReplace(curDest, curSource, minDiff)); //比如老版本10行,新版本5行;合并后10行不同,前5行是修改状态,后5行是新增状态 //minDiff = 5; if (diffDest > diffSource) { curDest += minDiff; report.Add(DiffResultSpan.CreateAddDestination(curDest, diffDest - diffSource)); } else//比如老版本3行,新版本5行;合并后5行不同,前3行是修改状态,后2行是删除状态 //minDiff = 3; { if (diffSource > diffDest) { curSource += minDiff; report.Add(DiffResultSpan.CreateDeleteSource(curSource, diffSource - diffDest)); } } } else //diffSource == 0表示老版本没有行,新版本有,表示新增行 { report.Add(DiffResultSpan.CreateAddDestination(curDest, diffDest)); } retval = true; } else { if (diffSource > 0) { report.Add(DiffResultSpan.CreateDeleteSource(curSource, diffSource)); retval = true; } } return(retval); }
private bool AddChanges( List <DiffResultSpan> report, int curDest, int nextDest, int curSource, int nextSource) { bool retval = false; int diffDest = nextDest - curDest; int diffSource = nextSource - curSource; int minDiff = 0; if (diffDest > 0) { if (diffSource > 0) { minDiff = Math.Min(diffDest, diffSource); report.Add(DiffResultSpan.CreateReplace(curDest, curSource, minDiff)); if (diffDest > diffSource) { curDest += minDiff; report.Add(DiffResultSpan.CreateAddDestination(curDest, diffDest - diffSource)); } else { if (diffSource > diffDest) { curSource += minDiff; report.Add(DiffResultSpan.CreateDeleteSource(curSource, diffSource - diffDest)); } } } else { report.Add(DiffResultSpan.CreateAddDestination(curDest, diffDest)); } retval = true; } else { if (diffSource > 0) { report.Add(DiffResultSpan.CreateDeleteSource(curSource, diffSource)); retval = true; } } return(retval); }