Skip to content

Commit e2934fe

Browse files
eugen-shulimovibbem
authored andcommitted
feat: create a method that projects text diffs
1 parent 92b9247 commit e2934fe

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

src/main/java/org/variantsync/diffdetective/variation/VariationUnparser.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,26 @@ public static <T extends Label> String variationDiffUnparser(VariationDiff<T> di
8282
public static String variationDiffUnparser(VariationDiff<DiffLinesLabel> diff) throws IOException {
8383
return variationDiffUnparser(diff, DiffLinesLabel::withInvalidLineNumbers);
8484
}
85+
86+
public static String undiff(String text, Time time) {
87+
StringBuilder result = new StringBuilder();
88+
String[] textSplit = text.split("\n");
89+
if (Time.AFTER == time) {
90+
for (String line : textSplit) {
91+
if (line.charAt(0) != '-') {
92+
result.append(line.substring(1));
93+
result.append("\n");
94+
}
95+
}
96+
return result.substring(0, result.length() - 1);
97+
} else {
98+
for (String line : textSplit) {
99+
if (line.charAt(0) != '+') {
100+
result.append(line.substring(1));
101+
result.append("\n");
102+
}
103+
}
104+
return result.substring(0, result.length() - 1);
105+
}
106+
}
85107
}

0 commit comments

Comments
 (0)