From 44f141dd24bf20b0e20b86c3cd644c6873fb5bcc Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Mon, 3 Jul 2023 18:07:45 +1200 Subject: [PATCH] LibDiff: Add Diff::write_context_header This is used to write a context patch header. --- Userland/Libraries/LibDiff/Format.cpp | 8 ++++++++ Userland/Libraries/LibDiff/Format.h | 1 + 2 files changed, 9 insertions(+) diff --git a/Userland/Libraries/LibDiff/Format.cpp b/Userland/Libraries/LibDiff/Format.cpp index 6417f6f9a5..f3c4c1c7ce 100644 --- a/Userland/Libraries/LibDiff/Format.cpp +++ b/Userland/Libraries/LibDiff/Format.cpp @@ -210,4 +210,12 @@ ErrorOr write_context(Hunk const& hunk, Stream& stream, ColorOutput color_ return write_hunk_as_context(split_lines.old_lines, split_lines.new_lines, hunk.location, stream, color_output); } +ErrorOr write_context_header(StringView old_path, StringView new_path, Stream& stream) +{ + TRY(stream.write_formatted("*** {}\n", old_path)); + TRY(stream.write_formatted("--- {}\n", new_path)); + + return stream.write_formatted("***************\n"); +} + } diff --git a/Userland/Libraries/LibDiff/Format.h b/Userland/Libraries/LibDiff/Format.h index a80d2fbb26..f6a83627a2 100644 --- a/Userland/Libraries/LibDiff/Format.h +++ b/Userland/Libraries/LibDiff/Format.h @@ -26,4 +26,5 @@ ErrorOr write_unified_header(StringView old_path, StringView new_path, Str ErrorOr write_normal(Hunk const& hunk, Stream& stream, ColorOutput color_output = ColorOutput::No); ErrorOr write_context(Hunk const& hunk, Stream& stream, ColorOutput color_output = ColorOutput::No); +ErrorOr write_context_header(StringView old_path, StringView new_path, Stream& stream); }