class String

Implementation of String#byteslice since RubyMotion (at least as of 3.6) does not implement it.

Public Instance Methods

byteslice(*args) click to toggle source

To get a byte range out of a possible multibyte string, force encoding to ASCII-8BIT and use regular string slice, then restore the original encoding

# File lib/motion-strscan/string.rb, line 9
def byteslice(*args)
  result = nil
  begin
    enc = self.encoding
    self.force_encoding('ASCII-8BIT')
    result = self.slice(*args)
  ensure
    self.force_encoding(enc)
  end
  result ? result.force_encoding(enc) : nil
end