Module: StringBytespliceCompat
- Defined in:
- lib/cabriolet/decompressors/quantum.rb
Instance Method Summary collapse
-
#bytesplice(index, length, other_string, other_index = 0, other_length = nil) ⇒ Object
Compatibility implementation of bytesplice for Ruby < 3.2 Uses clear/append which is slower but works with mutable strings.
Instance Method Details
#bytesplice(index, length, other_string, other_index = 0, other_length = nil) ⇒ Object
Compatibility implementation of bytesplice for Ruby < 3.2 Uses clear/append which is slower but works with mutable strings
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/cabriolet/decompressors/quantum.rb', line 10 def bytesplice(index, length, other_string, other_index = 0, other_length = nil) other_length ||= other_string.bytesize # Build new string content prefix = byteslice(0, index) middle = other_string.byteslice(other_index, other_length) suffix = byteslice((index + length)..-1) new_content = prefix + middle + suffix # Modify receiver in place clear self << new_content self end |