From f528aedc8573ade58d09b0dd7ecf8d54ec53c57f Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Tue, 27 Jun 2023 20:59:01 +1200 Subject: [PATCH] LibDiff: Add Diff::write_unified_header This is used to write a unified patch header. --- Userland/Libraries/LibDiff/Format.cpp | 8 ++++++++ Userland/Libraries/LibDiff/Format.h | 2 ++ 2 files changed, 10 insertions(+) diff --git a/Userland/Libraries/LibDiff/Format.cpp b/Userland/Libraries/LibDiff/Format.cpp index 996b56079b..7951a92d11 100644 --- a/Userland/Libraries/LibDiff/Format.cpp +++ b/Userland/Libraries/LibDiff/Format.cpp @@ -24,6 +24,14 @@ DeprecatedString generate_only_additions(StringView text) return builder.to_deprecated_string(); } +ErrorOr write_unified_header(StringView old_path, StringView new_path, Stream& stream) +{ + TRY(stream.write_formatted("--- {}\n", old_path)); + TRY(stream.write_formatted("+++ {}\n", new_path)); + + return {}; +} + ErrorOr write_unified(Hunk const& hunk, Stream& stream, ColorOutput color_output) { TRY(stream.write_formatted("{}\n", hunk.location)); diff --git a/Userland/Libraries/LibDiff/Format.h b/Userland/Libraries/LibDiff/Format.h index 0ae15ed258..303c804c24 100644 --- a/Userland/Libraries/LibDiff/Format.h +++ b/Userland/Libraries/LibDiff/Format.h @@ -21,6 +21,8 @@ enum class ColorOutput { }; ErrorOr write_unified(Hunk const& hunk, Stream& stream, ColorOutput color_output = ColorOutput::No); +ErrorOr write_unified_header(StringView old_path, StringView new_path, Stream& stream); + ErrorOr write_normal(Hunk const& hunk, Stream& stream, ColorOutput color_output = ColorOutput::No); }