class RSpec::Support::EncodedString

@private

Constants

REPLACE

Ruby’s default replacement string is:

U+FFFD ("\xEF\xBF\xBD"), for Unicode encoding forms, else
?      ("\x3F")
US_ASCII
UTF_8

Reduce allocations by storing constants.

Attributes

Public Class Methods

# File rspec-support/lib/rspec/support/encoded_string.rb, line 21
def initialize(string, encoding=nil)
  @encoding = encoding
  @source_encoding = detect_source_encoding(string)
  @string = matching_encoding(string)
end
# File rspec-support/lib/rspec/support/encoded_string.rb, line 17
def self.pick_encoding(source_a, source_b)
  Encoding.compatible?(source_a, source_b) || Encoding.default_external
end

Public Instance Methods

# File rspec-support/lib/rspec/support/encoded_string.rb, line 33
def <<(string)
  @string << matching_encoding(string)
end
# File rspec-support/lib/rspec/support/encoded_string.rb, line 38
def split(regex_or_string)
  @string.split(matching_encoding(regex_or_string))
rescue ArgumentError
  # JRuby raises an ArgumentError when splitting a source string that
  # contains invalid bytes.
  remove_invalid_bytes(@string).split regex_or_string
end
# File rspec-support/lib/rspec/support/encoded_string.rb, line 51
def to_s
  @string
end
Also aliased as: to_str
Alias for: to_s