/** * Construct an edit list containing a single edit. * * @param edit * the edit to return in the list. * @return list containing only {@code edit}. */ public static EditList singleton(Edit edit) { EditList res = new EditList(1); res.add(edit); return res; }
/** * Convert to a list describing the content edits performed on this file. * * @return a list describing the content edits performed on this file. */ public EditList toEditList() { final EditList r = new EditList(); for (HunkHeader hunk : hunks) r.addAll(hunk.toEditList()); return r; }
/** * Returns a git-style diff between the two unix strings. * * Output has no trailing newlines. * * Boolean args determine whether whitespace or line endings will be visible. */ private static String diffWhitespaceLineEndings(String dirty, String clean, boolean whitespace, boolean lineEndings) throws IOException { dirty = visibleWhitespaceLineEndings(dirty, whitespace, lineEndings); clean = visibleWhitespaceLineEndings(clean, whitespace, lineEndings); RawText a = new RawText(dirty.getBytes(StandardCharsets.UTF_8)); RawText b = new RawText(clean.getBytes(StandardCharsets.UTF_8)); EditList edits = new EditList(); edits.addAll(MyersDiff.INSTANCE.diff(RawTextComparator.DEFAULT, a, b)); ByteArrayOutputStream out = new ByteArrayOutputStream(); try (DiffFormatter formatter = new DiffFormatter(out)) { formatter.format(edits, a, b); } String formatted = out.toString(StandardCharsets.UTF_8.name()); // we don't need the diff to show this, since we display newlines ourselves formatted = formatted.replace("\\ No newline at end of file\n", ""); return NEWLINE_MATCHER.trimTrailingFrom(formatted); }
/** {@inheritDoc} */ @Override public <S extends Sequence> EditList diffNonCommon( SequenceComparator<? super S> cmp, S a, S b) { HashedSequencePair<S> p = new HashedSequencePair<>(cmp, a, b); HashedSequenceComparator<S> hc = p.getComparator(); HashedSequence<S> ha = p.getA(); HashedSequence<S> hb = p.getB(); p = null; EditList res = new EditList(); Edit region = new Edit(0, a.size(), 0, b.size()); diffNonCommon(res, hc, ha, hb, region); return res; }
editList = new EditList(); final byte[] buf = file.buf; int c = nextLF(buf, startOffset);
return new EditList(0);
/** * Construct an edit list containing a single edit. * * @param edit * the edit to return in the list. * @return list containing only {@code edit}. */ public static EditList singleton(Edit edit) { EditList res = new EditList(1); res.add(edit); return res; }
/** * Construct an edit list containing a single edit. * * @param edit * the edit to return in the list. * @return list containing only {@code edit}. */ public static EditList singleton(Edit edit) { EditList res = new EditList(1); res.add(edit); return res; }
/** @return a list describing the content edits performed on this file. */ public EditList toEditList() { final EditList r = new EditList(); for (final HunkHeader hunk : hunks) r.addAll(hunk.toEditList()); return r; }
/** * Convert to a list describing the content edits performed on this file. * * @return a list describing the content edits performed on this file. */ public EditList toEditList() { final EditList r = new EditList(); for (HunkHeader hunk : hunks) r.addAll(hunk.toEditList()); return r; }
/** * Get the differences in git format. * * @param string1 the string1 * @param string2 the string2 * @return the diff * @throws IOException Signals that an I/O exception has occurred. */ private String getDiffinGitFormat(String string1, String string2) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); RawText rt1 = new RawText(string1.getBytes(Charsets.UTF_8)); RawText rt2 = new RawText(string2.getBytes(Charsets.UTF_8)); EditList diffList = new EditList(); diffList.addAll(new HistogramDiff().diff(RawTextComparator.DEFAULT, rt1, rt2)); new DiffFormatter(out).format(diffList, rt1, rt2); return out.toString(Charsets.UTF_8.name()); }
/** * Get the differences in git format. * * @param string1 the string1 * @param string2 the string2 * @return the diff * @throws IOException Signals that an I/O exception has occurred. */ private String getDiffinGitFormat(String string1, String string2) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); RawText rt1 = new RawText(string1.getBytes(Charsets.UTF_8)); RawText rt2 = new RawText(string2.getBytes(Charsets.UTF_8)); EditList diffList = new EditList(); diffList.addAll(new HistogramDiff().diff(RawTextComparator.DEFAULT, rt1, rt2)); new DiffFormatter(out).format(diffList, rt1, rt2); return out.toString(Charsets.UTF_8.name()); }
/** * Returns a git-style diff between the two unix strings. * * Output has no trailing newlines. * * Boolean args determine whether whitespace or line endings will be visible. */ private static String diffWhitespaceLineEndings(String dirty, String clean, boolean whitespace, boolean lineEndings) throws IOException { dirty = visibleWhitespaceLineEndings(dirty, whitespace, lineEndings); clean = visibleWhitespaceLineEndings(clean, whitespace, lineEndings); RawText a = new RawText(dirty.getBytes(StandardCharsets.UTF_8)); RawText b = new RawText(clean.getBytes(StandardCharsets.UTF_8)); EditList edits = new EditList(); edits.addAll(MyersDiff.INSTANCE.diff(RawTextComparator.DEFAULT, a, b)); ByteArrayOutputStream out = new ByteArrayOutputStream(); try (DiffFormatter formatter = new DiffFormatter(out)) { formatter.format(edits, a, b); } String formatted = out.toString(StandardCharsets.UTF_8.name()); // we don't need the diff to show this, since we display newlines ourselves formatted = formatted.replace("\\ No newline at end of file\n", ""); return NEWLINE_MATCHER.trimTrailingFrom(formatted); }
editList = new EditList(0); } else { p.loadText(reader);
@Override public <S extends Sequence> EditList diffNonCommon( SequenceComparator<? super S> cmp, S a, S b) { HashedSequencePair<S> p = new HashedSequencePair<S>(cmp, a, b); HashedSequenceComparator<S> hc = p.getComparator(); HashedSequence<S> ha = p.getA(); HashedSequence<S> hb = p.getB(); p = null; EditList res = new EditList(); Edit region = new Edit(0, a.size(), 0, b.size()); diffNonCommon(res, hc, ha, hb, region); return res; }
/** {@inheritDoc} */ @Override public <S extends Sequence> EditList diffNonCommon( SequenceComparator<? super S> cmp, S a, S b) { HashedSequencePair<S> p = new HashedSequencePair<>(cmp, a, b); HashedSequenceComparator<S> hc = p.getComparator(); HashedSequence<S> ha = p.getA(); HashedSequence<S> hb = p.getB(); p = null; EditList res = new EditList(); Edit region = new Edit(0, a.size(), 0, b.size()); diffNonCommon(res, hc, ha, hb, region); return res; }
editList = new EditList(); final byte[] buf = file.buf; int c = nextLF(buf, startOffset);
return new EditList(0);