Class: RSpec::Support::EncodedString
- Defined in:
- lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support/encoded_string.rb
Constant Summary collapse
- UTF_8 =
Reduce allocations by storing constants.
"UTF-8"
- US_ASCII =
"US-ASCII"
- REPLACE =
Ruby’s default replacement string is:
U+FFFD ("\xEF\xBF\xBD"), for Unicode encoding forms, else ? ("\x3F")
"?"
Instance Attribute Summary collapse
-
#source_encoding ⇒ Object
readonly
Returns the value of attribute source_encoding.
Class Method Summary collapse
Instance Method Summary collapse
- #<<(string) ⇒ Object
-
#initialize(string, encoding = nil) ⇒ EncodedString
constructor
A new instance of EncodedString.
- #split(regex_or_string) ⇒ Object
- #to_s ⇒ Object (also: #to_str)
Constructor Details
#initialize(string, encoding = nil) ⇒ EncodedString
Returns a new instance of EncodedString.
14 15 16 17 18 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support/encoded_string.rb', line 14 def initialize(string, encoding=nil) @encoding = encoding @source_encoding = detect_source_encoding(string) @string = matching_encoding(string) end |
Instance Attribute Details
#source_encoding ⇒ Object (readonly)
Returns the value of attribute source_encoding.
19 20 21 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support/encoded_string.rb', line 19 def source_encoding @source_encoding end |
Class Method Details
.pick_encoding(_source_a, _source_b) ⇒ Object
141 142 143 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support/encoded_string.rb', line 141 def self.pick_encoding(source_a, source_b) Encoding.compatible?(source_a, source_b) || Encoding.default_external end |
Instance Method Details
#<<(string) ⇒ Object
26 27 28 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support/encoded_string.rb', line 26 def <<(string) @string << matching_encoding(string) end |
#split(regex_or_string) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support/encoded_string.rb', line 31 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 |
#to_s ⇒ Object Also known as: to_str
44 45 46 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support/encoded_string.rb', line 44 def to_s @string end |