Mercurial Hosting > luan
changeset 1809:90187946d1a4
minor
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 12 May 2024 17:15:33 -0600 |
parents | 69623c62aa34 |
children | 3c43b07e12b7 |
files | src/goodjava/util/LineDiff.java src/luan/modules/StringLuan.java |
diffstat | 2 files changed, 15 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/src/goodjava/util/LineDiff.java Sun May 12 15:58:30 2024 -0600 +++ b/src/goodjava/util/LineDiff.java Sun May 12 17:15:33 2024 -0600 @@ -13,13 +13,15 @@ public static class Diff { public final char operation; - public final int line; public final String text; + public final int lineOld; + public final int lineNew; - private Diff(char operation,String[] lines,int i) { + private Diff(char operation,String line,int iOld,int iNew) { this.operation = operation; - this.line = i+1; - this.text = lines[i]; + this.text = line; + this.lineOld = iOld + 1; + this.lineNew = iNew + 1; } } @@ -67,18 +69,22 @@ iOld++; iNew++; } else if (opt[iOld+1][iNew] >= opt[iOld][iNew+1]) { - diffs.add( new Diff( DELETE, oldLines, iOld++ ) ); + diffs.add( new Diff( DELETE, oldLines[iOld], iOld, iNew ) ); + iOld++; } else { - diffs.add( new Diff( INSERT, newLines, iNew++ ) ); + diffs.add( new Diff( INSERT, newLines[iNew], iOld, iNew ) ); + iNew++; } } // dump out one remainder of one string if the other is exhausted while( iOld < nOld ) { - diffs.add( new Diff( DELETE, oldLines, iOld++ ) ); + diffs.add( new Diff( DELETE, oldLines[iOld], iOld, iNew ) ); + iOld++; } while( iNew < nNew ) { - diffs.add( new Diff( INSERT, newLines, iNew++ ) ); + diffs.add( new Diff( INSERT, newLines[iNew], iOld, iNew ) ); + iNew++; } return diffs;
--- a/src/luan/modules/StringLuan.java Sun May 12 15:58:30 2024 -0600 +++ b/src/luan/modules/StringLuan.java Sun May 12 17:15:33 2024 -0600 @@ -162,7 +162,7 @@ List<LineDiff.Diff> diffs = LineDiff.diff(oldStr,newStr); StringBuilder sb = new StringBuilder(); for( LineDiff.Diff diff : diffs ) { - sb.append(diff.operation).append(' ').append(diff.line).append(" - ").append(diff.text).append('\n'); + sb.append(diff.operation).append(' ').append(diff.lineOld).append(' ').append(diff.lineNew).append(" - ").append(diff.text).append('\n'); } return sb.toString(); }