diff options
author | Daniel Bertalan <dani@danielbertalan.dev> | 2022-02-25 22:06:54 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-03-08 23:30:47 +0100 |
commit | 4b4177f39c46eb030b01b9aeae954725391ce6cf (patch) | |
tree | ed8b379a71e2f17c0e38f5afc992cdff14269bb3 /Userland/Libraries/LibDiff/Generator.cpp | |
parent | 7bd68c86d3ed6cac4c3abb165b3cc6b91973d41a (diff) | |
download | serenity-4b4177f39c46eb030b01b9aeae954725391ce6cf.zip |
LibDiff: Generate hunks for new/deleted files
Previously we would fail to generate any hunks if the old or the new
file was empty. We now do, with the original/target line index set to 0,
as specified by POSIX.
Diffstat (limited to 'Userland/Libraries/LibDiff/Generator.cpp')
-rw-r--r-- | Userland/Libraries/LibDiff/Generator.cpp | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/Userland/Libraries/LibDiff/Generator.cpp b/Userland/Libraries/LibDiff/Generator.cpp index 43bdee9207..cf65e18b61 100644 --- a/Userland/Libraries/LibDiff/Generator.cpp +++ b/Userland/Libraries/LibDiff/Generator.cpp @@ -107,12 +107,12 @@ Vector<Hunk> from_text(StringView old_text, StringView new_text) } } - while (i < old_lines.size() && new_lines.size() > 0) { - update_hunk(i, new_lines.size() - 1, Direction::Right); // Remove a line + while (i < old_lines.size()) { + update_hunk(i, new_lines.is_empty() ? 0 : new_lines.size() - 1, Direction::Right); // Remove a line ++i; } - while (j < new_lines.size() && old_lines.size() > 0) { - update_hunk(old_lines.size() - 1, j, Direction::Down); // Add a line + while (j < new_lines.size()) { + update_hunk(old_lines.is_empty() ? 0 : old_lines.size() - 1, j, Direction::Down); // Add a line ++j; } |