ParseTextFragments parses text fragments until the next file header or the end of the stream and attaches them to the given file. It returns the number of fragments that were added.
(f *File)
| 11 | // end of the stream and attaches them to the given file. It returns the number |
| 12 | // of fragments that were added. |
| 13 | func (p *parser) ParseTextFragments(f *File) (n int, err error) { |
| 14 | for { |
| 15 | frag, err := p.ParseTextFragmentHeader() |
| 16 | if err != nil { |
| 17 | return n, err |
| 18 | } |
| 19 | if frag == nil { |
| 20 | return n, nil |
| 21 | } |
| 22 | |
| 23 | if f.IsNew && frag.OldLines > 0 { |
| 24 | return n, p.Errorf(-1, "new file depends on old contents") |
| 25 | } |
| 26 | if f.IsDelete && frag.NewLines > 0 { |
| 27 | return n, p.Errorf(-1, "deleted file still has contents") |
| 28 | } |
| 29 | |
| 30 | if err := p.ParseTextChunk(frag); err != nil { |
| 31 | return n, err |
| 32 | } |
| 33 | |
| 34 | f.TextFragments = append(f.TextFragments, frag) |
| 35 | n++ |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | func (p *parser) ParseTextFragmentHeader() (*TextFragment, error) { |
| 40 | const ( |