Sha256: 017ef48e37edfd1e13b1588c6762437ae1e2bb7bb06742ede7b5c839345de644

Contents?: true

Size: 750 Bytes

Versions: 6

Compression:

Stored size: 750 Bytes

Contents

# encoding: utf-8
# frozen_string_literal: true

module RuboCop
  module Cop
    # Common functionality for obtaining source ranges from regexp matches
    module MatchRange
      # Return a new `Range` covering the first matching group number for each
      # match of `regex` inside `range`
      def each_match_range(range, regex)
        range.source.scan(regex) do
          yield match_range(range, Regexp.last_match)
        end
      end

      # For a `match` inside `range`, return a new `Range` covering the match
      def match_range(range, match)
        Parser::Source::Range.new(
          range.source_buffer,
          range.begin_pos + match.begin(1),
          range.begin_pos + match.end(1)
        )
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
fluent-plugin-detect-memb-exceptions-0.0.2 vendor/bundle/ruby/2.0.0/gems/rubocop-0.42.0/lib/rubocop/cop/mixin/match_range.rb
fluent-plugin-detect-memb-exceptions-0.0.1 vendor/bundle/ruby/2.0.0/gems/rubocop-0.42.0/lib/rubocop/cop/mixin/match_range.rb
rubocop-0.42.0 lib/rubocop/cop/mixin/match_range.rb
rubocop-0.41.2 lib/rubocop/cop/mixin/match_range.rb
rubocop-0.41.1 lib/rubocop/cop/mixin/match_range.rb
rubocop-0.41.0 lib/rubocop/cop/mixin/match_range.rb