Add basic fragment parsing function

This should work, but does no validation on the fragment after parsing.
This commit is contained in:
Billy Keyes
2019-03-28 23:10:41 -07:00
parent 9b0fc30459
commit 7483884180
2 changed files with 85 additions and 7 deletions
+23
View File
@@ -35,8 +35,31 @@ type Fragment struct {
NewPosition int64
NewLines int64
LinesAdded int64
LinesDeleted int64
Lines []FragmentLine
}
// FragmentLine is a line in a fragment.
type FragmentLine struct {
Op LineOp
Line string
}
// LineOp describes the type of a fragment line: context, added, or removed.
type LineOp int
const (
// OpContext indicates a context line
OpContext LineOp = iota
// OpDelete indicates a deleted line
OpDelete
// OpAdd indicates an added line
OpAdd
)
// Header returns the cannonical header of this fragment.
func (f *Fragment) Header() string {
return fmt.Sprintf("@@ -%d,%d +%d,%d @@ %s", f.OldPosition, f.OldLines, f.NewPosition, f.NewLines, f.Comment)