Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit81085d3

Browse files
ibrahimAliiwumpz
authored andcommitted
Extract duplicate code into method. (#58)
* Extract duplicate code into method.* fix conflicts.
1 parent15a5f06 commit81085d3

File tree

1 file changed

+11
-24
lines changed

1 file changed

+11
-24
lines changed

‎java-diff-utils/src/main/java/com/github/difflib/UnifiedDiffUtils.java

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -59,25 +59,7 @@ public static Patch<String> parseUnifiedDiff(List<String> diff) {
5959
Matcherm =UNIFIED_DIFF_CHUNK_REGEXP.matcher(line);
6060
if (m.find()) {
6161
// Process the lines in the previous chunk
62-
if (!rawChunk.isEmpty()) {
63-
List<String>oldChunkLines =newArrayList<>();
64-
List<String>newChunkLines =newArrayList<>();
65-
66-
for (String[]raw_line :rawChunk) {
67-
tag =raw_line[0];
68-
rest =raw_line[1];
69-
if (" ".equals(tag) ||"-".equals(tag)) {
70-
oldChunkLines.add(rest);
71-
}
72-
if (" ".equals(tag) ||"+".equals(tag)) {
73-
newChunkLines.add(rest);
74-
}
75-
}
76-
patch.addDelta(newChangeDelta<>(newChunk<>(
77-
old_ln -1,oldChunkLines),newChunk<>(
78-
new_ln -1,newChunkLines)));
79-
rawChunk.clear();
80-
}
62+
processLinesInPrevChunk(rawChunk,patch,old_ln,new_ln);
8163
// Parse the @@ header
8264
old_ln =m.group(1) ==null ?1 :Integer.parseInt(m.group(1));
8365
new_ln =m.group(3) ==null ?1 :Integer.parseInt(m.group(3));
@@ -102,6 +84,14 @@ public static Patch<String> parseUnifiedDiff(List<String> diff) {
10284
}
10385

10486
// Process the lines in the last chunk
87+
processLinesInPrevChunk(rawChunk,patch,old_ln,new_ln);
88+
89+
returnpatch;
90+
}
91+
92+
privatestaticvoidprocessLinesInPrevChunk(List<String[]>rawChunk,Patch<String>patch,intold_ln,intnew_ln) {
93+
Stringtag;
94+
Stringrest;
10595
if (!rawChunk.isEmpty()) {
10696
List<String>oldChunkLines =newArrayList<>();
10797
List<String>newChunkLines =newArrayList<>();
@@ -116,14 +106,11 @@ public static Patch<String> parseUnifiedDiff(List<String> diff) {
116106
newChunkLines.add(rest);
117107
}
118108
}
119-
120109
patch.addDelta(newChangeDelta<>(newChunk<>(
121-
old_ln -1,oldChunkLines),newChunk<>(new_ln -1,
122-
newChunkLines)));
110+
old_ln -1,oldChunkLines),newChunk<>(
111+
new_ln -1,newChunkLines)));
123112
rawChunk.clear();
124113
}
125-
126-
returnpatch;
127114
}
128115

129116
/**

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp