# encoding: UTF-8
# frozen_string_literal: true
module Capybara
# @api private
module Helpers
extend 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, regexp_options=nil, exact=false)
if text.is_a?(Regexp)
text
else
escaped = Regexp.escape(normalize_whitespace(text))
escaped = "\\A#{escaped}\\z" if exact
Regexp.new(escaped, regexp_options)
end
end
##
#
# Injects a `