10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/gitlab/word_diff/parser.rb', line 10
def parse(lines, diff_file: nil)
return [] if lines.blank?
Enumerator.new do |yielder|
@chunks = ChunkCollection.new
@counter = PositionsCounter.new
lines.each do |line|
segment = LineProcessor.new(line).
case segment
when Segments::DiffHunk
next if segment.first_line?
counter.set_pos_num(old: segment.pos_old, new: segment.pos_new)
yielder << build_line(segment.to_s, 'match', parent_file: diff_file)
when Segments::Chunk
@chunks.add(segment)
when Segments::Newline
yielder << build_line(@chunks.content, nil, parent_file: diff_file).tap { |line| line.set_marker_ranges(@chunks.marker_ranges) }
@chunks.reset
counter.increase_pos_num
end
end
end
end
|