Class: RSpec::Support::EncodedString

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/support/encoded_string.rb

Constant Summary collapse

UTF_8 =

Reduce allocations by storing constants.

"UTF-8"
US_ASCII =
'US-ASCII'
REPLACE =

else: ‘?’ 63.chr (“x3F”)

"?"
ENCODE_UNCONVERTABLE_BYTES =
{
  :invalid => :replace,
  :undef   => :replace
}
ENCODE_NO_CONVERTER =
{
  :invalid => :replace,
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string, encoding = nil) ⇒ EncodedString

Returns a new instance of EncodedString.



18
19
20
21
22
# File 'lib/rspec/support/encoded_string.rb', line 18

def initialize(string, encoding=nil)
  @encoding = encoding
  @source_encoding = detect_source_encoding(string)
  @string = matching_encoding(string)
end

Instance Attribute Details

#source_encodingObject (readonly)

Returns the value of attribute source_encoding.



23
24
25
# File 'lib/rspec/support/encoded_string.rb', line 23

def source_encoding
  @source_encoding
end

Instance Method Details

#<<(string) ⇒ Object



30
31
32
# File 'lib/rspec/support/encoded_string.rb', line 30

def <<(string)
  @string << matching_encoding(string)
end

#split(regex_or_string) ⇒ Object



34
35
36
# File 'lib/rspec/support/encoded_string.rb', line 34

def split(regex_or_string)
  @string.split(matching_encoding(regex_or_string))
end

#to_sObject Also known as: to_str



38
39
40
# File 'lib/rspec/support/encoded_string.rb', line 38

def to_s
  @string
end