# frozen_string_literal: true
module Capybara
# @api private
module Helpers
module_function
##
# @deprecated
# 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)
warn 'DEPRECATED: Capybara::Helpers::normalize_whitespace is deprecated, please update your driver'
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
# @param [Boolean] exact (false) Whether or not this should be an exact text match
# @param [Fixnum, Boolean, nil] options Options passed to Regexp.new when creating the Regexp
# @return [Regexp] Regexp to match the passed in text and options
#
def to_regexp(text, exact: false, all_whitespace: false, options: nil)
return text if text.is_a?(Regexp)
escaped = Regexp.escape(text)
escaped = escaped.gsub('\\ ', '[[:blank:]]') if all_whitespace
escaped = "\\A#{escaped}\\z" if exact
Regexp.new(escaped, options)
end
##
#
# Injects a `