Method: RuboCop::Cop::Performance::StartWith#literal_at_start?

Defined in:
lib/rubocop/cop/performance/start_with.rb

#literal_at_start?(regex_str) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
30
31
32
33
34
35
# File 'lib/rubocop/cop/performance/start_with.rb', line 27

def literal_at_start?(regex_str)
  # is this regexp 'literal' in the sense of only matching literal
  # chars, rather than using metachars like . and * and so on?
  # also, is it anchored at the start of the string?
  # (tricky: \s, \d, and so on are metacharacters, but other characters
  #  escaped with a slash are just literals. LITERAL_REGEX takes all
  #  that into account.)
  regex_str =~ /\A\\A(?:#{LITERAL_REGEX})+\z/
end