mirror of
https://github.com/java-diff-utils/java-diff-utils.git
synced 2026-03-13 10:11:17 +08:00
Extract duplicate code into method. (#58)
* Extract duplicate code into method. * fix conflicts.
This commit is contained in:
committed by
Tobias
parent
15a5f060b3
commit
81085d368c
@@ -59,25 +59,7 @@ public final class UnifiedDiffUtils {
|
||||
Matcher m = UNIFIED_DIFF_CHUNK_REGEXP.matcher(line);
|
||||
if (m.find()) {
|
||||
// Process the lines in the previous chunk
|
||||
if (!rawChunk.isEmpty()) {
|
||||
List<String> oldChunkLines = new ArrayList<>();
|
||||
List<String> newChunkLines = new ArrayList<>();
|
||||
|
||||
for (String[] raw_line : rawChunk) {
|
||||
tag = raw_line[0];
|
||||
rest = raw_line[1];
|
||||
if (" ".equals(tag) || "-".equals(tag)) {
|
||||
oldChunkLines.add(rest);
|
||||
}
|
||||
if (" ".equals(tag) || "+".equals(tag)) {
|
||||
newChunkLines.add(rest);
|
||||
}
|
||||
}
|
||||
patch.addDelta(new ChangeDelta<>(new Chunk<>(
|
||||
old_ln - 1, oldChunkLines), new Chunk<>(
|
||||
new_ln - 1, newChunkLines)));
|
||||
rawChunk.clear();
|
||||
}
|
||||
processLinesInPrevChunk(rawChunk, patch, old_ln, new_ln);
|
||||
// Parse the @@ header
|
||||
old_ln = m.group(1) == null ? 1 : Integer.parseInt(m.group(1));
|
||||
new_ln = m.group(3) == null ? 1 : Integer.parseInt(m.group(3));
|
||||
@@ -102,6 +84,14 @@ public final class UnifiedDiffUtils {
|
||||
}
|
||||
|
||||
// Process the lines in the last chunk
|
||||
processLinesInPrevChunk(rawChunk, patch, old_ln, new_ln);
|
||||
|
||||
return patch;
|
||||
}
|
||||
|
||||
private static void processLinesInPrevChunk(List<String[]> rawChunk, Patch<String> patch, int old_ln, int new_ln) {
|
||||
String tag;
|
||||
String rest;
|
||||
if (!rawChunk.isEmpty()) {
|
||||
List<String> oldChunkLines = new ArrayList<>();
|
||||
List<String> newChunkLines = new ArrayList<>();
|
||||
@@ -116,14 +106,11 @@ public final class UnifiedDiffUtils {
|
||||
newChunkLines.add(rest);
|
||||
}
|
||||
}
|
||||
|
||||
patch.addDelta(new ChangeDelta<>(new Chunk<>(
|
||||
old_ln - 1, oldChunkLines), new Chunk<>(new_ln - 1,
|
||||
newChunkLines)));
|
||||
old_ln - 1, oldChunkLines), new Chunk<>(
|
||||
new_ln - 1, newChunkLines)));
|
||||
rawChunk.clear();
|
||||
}
|
||||
|
||||
return patch;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user