Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/motion-strscan/string.rb
Overview
Implementation of String#byteslice since RubyMotion (at least as of 3.6) does not implement it.
Instance Method Summary collapse
-
#byteslice(*args) ⇒ Object
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 ——————————————————————————.
Instance Method Details
#byteslice(*args) ⇒ Object
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
9 10 11 12 13 14 15 16 17 18 19 |
# 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 |