class String
Public Instance Methods
binary?()
click to toggle source
@return [Bool]
`true` if `self` is binary, `false` if regular text.
# File lib/raptor-io/ruby/string.rb, line 21 def binary? encoding == Encoding::ASCII_8BIT || index( "\x00" ) || count( "\x00-\x7F", "^ -~\t\r\n").fdiv( length ) > 0.3 end
force_utf8()
click to toggle source
@return [String] Copy of ‘self`, {#force_utf8! forced to UTF-8}.
# File lib/raptor-io/ruby/string.rb, line 15 def force_utf8 dup.force_utf8! end
force_utf8!()
click to toggle source
Forces ‘self` to UTF-8 and replaces invalid characters.
# File lib/raptor-io/ruby/string.rb, line 9 def force_utf8! force_encoding( 'utf-8' ) encode!( 'utf-16be', invalid: :replace, undef: :replace ).encode( 'utf-8' ) end
repack()
click to toggle source
@return [String] ‘self` with 8-bit unsigned characters.
# File lib/raptor-io/ruby/string.rb, line 4 def repack unpack( 'C*' ).pack( 'C*' ) end