mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:57:34 +00:00
LibDiff: Make parsing of unified hunks more robust
Parsing of the unified hunks now verifies that the expected number of lines given by the unified location at the beginning of that hunk are actually in that hunk. Furthermore, we no longer crash when given a bogus unified range. As a further benefit, this begins the scaffolding for a patch parser which should assist us in parsing full patches - even when we are not aware of the format that a patch has been written in.
This commit is contained in:
parent
b2d33c5689
commit
ef45221c21
3 changed files with 102 additions and 72 deletions
|
@ -9,6 +9,7 @@
|
|||
|
||||
#include <AK/Assertions.h>
|
||||
#include <AK/Format.h>
|
||||
#include <AK/GenericLexer.h>
|
||||
#include <AK/String.h>
|
||||
#include <AK/StringView.h>
|
||||
#include <AK/Vector.h>
|
||||
|
@ -58,10 +59,21 @@ struct Hunk {
|
|||
Vector<Line> lines;
|
||||
};
|
||||
|
||||
ErrorOr<Vector<Hunk>> parse_hunks(StringView diff);
|
||||
HunkLocation parse_hunk_location(StringView location_line);
|
||||
class Parser : public GenericLexer {
|
||||
public:
|
||||
using GenericLexer::GenericLexer;
|
||||
|
||||
ErrorOr<Vector<Hunk>> parse_hunks();
|
||||
|
||||
private:
|
||||
Optional<HunkLocation> consume_unified_location();
|
||||
bool consume_line_number(size_t& number);
|
||||
};
|
||||
|
||||
ErrorOr<Vector<Hunk>> parse_hunks(StringView diff);
|
||||
|
||||
}
|
||||
|
||||
template<>
|
||||
struct AK::Formatter<Diff::Line::Operation> : Formatter<FormatString> {
|
||||
ErrorOr<void> format(FormatBuilder& builder, Diff::Line::Operation operation)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue