summaryrefslogtreecommitdiff
path: root/lib/gitlab/string_regex_marker.rb
blob: f1982ff914ce1de8a5eb11ae96d921c7a4eca9e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# frozen_string_literal: true

module Gitlab
  class StringRegexMarker < StringRangeMarker
    # rubocop: disable CodeReuse/ActiveRecord
    def mark(regex, group: 0, &block)
      ranges = []

      raw_line.scan(regex) do
        begin_index, end_index = Regexp.last_match.offset(group)

        ranges << (begin_index..(end_index - 1))
      end

      super(ranges, &block)
    end
    # rubocop: enable CodeReuse/ActiveRecord
  end
end