1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 15:17:36 +00:00

LibDiff: Port Diff::Hunk from DeprecatedString to String

Removing the last instance of DeprecatedString in this library! :^)
This commit is contained in:
Shannon Booth 2023-06-24 13:17:24 +12:00 committed by Andreas Kling
parent 9dc92f19b8
commit d3a27eeaf2
3 changed files with 7 additions and 7 deletions

View file

@ -72,9 +72,9 @@ ErrorOr<Vector<Hunk>> from_text(StringView old_text, StringView new_text)
cur_hunk = { i, j, {}, {} }; cur_hunk = { i, j, {}, {} };
} }
if (direction == Direction::Down) { if (direction == Direction::Down) {
TRY(cur_hunk.added_lines.try_append(new_lines[j])); TRY(cur_hunk.added_lines.try_append(TRY(String::from_utf8(new_lines[j]))));
} else if (direction == Direction::Right) { } else if (direction == Direction::Right) {
TRY(cur_hunk.removed_lines.try_append(old_lines[i])); TRY(cur_hunk.removed_lines.try_append(TRY(String::from_utf8(old_lines[i]))));
} }
return {}; return {};

View file

@ -41,12 +41,12 @@ ErrorOr<Vector<Hunk>> parse_hunks(StringView diff)
hunk.target_start_line = current_location.target_start_line; hunk.target_start_line = current_location.target_start_line;
while (line_index < diff_lines.size() && diff_lines[line_index][0] == '-') { while (line_index < diff_lines.size() && diff_lines[line_index][0] == '-') {
TRY(hunk.removed_lines.try_append(diff_lines[line_index].substring_view(1, diff_lines[line_index].length() - 1))); TRY(hunk.removed_lines.try_append(TRY(String::from_utf8(diff_lines[line_index].substring_view(1, diff_lines[line_index].length() - 1)))));
current_location.apply_offset(1, HunkLocation::LocationType::Original); current_location.apply_offset(1, HunkLocation::LocationType::Original);
++line_index; ++line_index;
} }
while (line_index < diff_lines.size() && diff_lines[line_index][0] == '+') { while (line_index < diff_lines.size() && diff_lines[line_index][0] == '+') {
TRY(hunk.added_lines.try_append(diff_lines[line_index].substring_view(1, diff_lines[line_index].length() - 1))); TRY(hunk.added_lines.try_append(TRY(String::from_utf8(diff_lines[line_index].substring_view(1, diff_lines[line_index].length() - 1)))));
current_location.apply_offset(1, HunkLocation::LocationType::Target); current_location.apply_offset(1, HunkLocation::LocationType::Target);
++line_index; ++line_index;
} }

View file

@ -6,7 +6,7 @@
#pragma once #pragma once
#include <AK/DeprecatedString.h> #include <AK/String.h>
#include <AK/StringView.h> #include <AK/StringView.h>
#include <AK/Vector.h> #include <AK/Vector.h>
@ -29,8 +29,8 @@ struct HunkLocation {
struct Hunk { struct Hunk {
size_t original_start_line { 0 }; size_t original_start_line { 0 };
size_t target_start_line { 0 }; size_t target_start_line { 0 };
Vector<DeprecatedString> removed_lines; Vector<String> removed_lines;
Vector<DeprecatedString> added_lines; Vector<String> added_lines;
}; };
ErrorOr<Vector<Hunk>> parse_hunks(StringView diff); ErrorOr<Vector<Hunk>> parse_hunks(StringView diff);