mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
8852e4dc20
`[[:space:]]` works like `\s` in regexes, except it is encoding aware.
32 lines
826 B
Ruby
32 lines
826 B
Ruby
# encoding: UTF-8
|
|
|
|
module Capybara
|
|
module Helpers
|
|
class << self
|
|
##
|
|
#
|
|
# Normalizes whitespace space by stripping leading and trailing
|
|
# whitespace and replacing sequences of whitespace characters
|
|
# with a single space.
|
|
#
|
|
# @param [String] text Text to normalize
|
|
# @return [String] Normalized text
|
|
#
|
|
def normalize_whitespace(text)
|
|
text.to_s.gsub(/[[:space:]]+/, ' ').strip
|
|
end
|
|
|
|
##
|
|
#
|
|
# Escapes any characters that would have special meaning in a regexp
|
|
# if text is not a regexp
|
|
#
|
|
# @param [String] text Text to escape
|
|
# @return [String] Escaped text
|
|
#
|
|
def to_regexp(text)
|
|
text.is_a?(Regexp) ? text : Regexp.escape(normalize_whitespace(text))
|
|
end
|
|
end
|
|
end
|
|
end
|