Class: Capybara::Selector::CSS

Inherits:
Object
  • Object
show all
Defined in:
lib/capybara/selector/css.rb

Constant Summary collapse

S =
'\u{80}-\u{D7FF}\u{E000}-\u{FFFD}\u{10000}-\u{10FFFF}'
H =
/[0-9a-fA-F]/
UNICODE =
/\\#{H}{1,6}[ \t\r\n\f]?/
NONASCII =
/[#{S}]/
ESCAPE =
/#{UNICODE}|\\[ -~#{S}]/
NMSTART =
/[_a-zA-Z]|#{NONASCII}|#{ESCAPE}/

Class Method Summary collapse

Class Method Details

.escape(str) ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/capybara/selector/css.rb', line 6

def self.escape(str)
  value = str.dup
  out = +""
  out << value.slice!(0...1) if value =~ /^[-_]/
  out << (value[0] =~ NMSTART ? value.slice!(0...1) : escape_char(value.slice!(0...1)))
  out << value.gsub(/[^a-zA-Z0-9_-]/) { |c| escape_char c }
  out
end

.escape_char(c) ⇒ Object



15
16
17
# File 'lib/capybara/selector/css.rb', line 15

def self.escape_char(c)
  c =~ %r{[ -/:-~]} ? "\\#{c}" : format("\\%06x", c.ord)
end