Slice(T)
Inherits Logos::Source < Comparable < Indexable::Mutable < Indexable < Enumerable < Iterable < Struct < Value < Object
Implement Source for Slice(UInt8)
Instance methods
Check if index is valid for this Source, that is:
- It's not larger than the byte length of the
Source. - (
Stringonly) It doesn't land in the middle of a UTF-8 code point.
Read bytes bytes starting at offset. Returns nil when reading
out of bounds would occur.
Read a single byte at offset. Returns nil when reading
out of bounds would occur.
This is very useful for matching fixed-size byte arrays, and tends to be very fast at it too, since the compiler knows the byte length.
Get a slice of the source at given range. This is analogous to
slice[range]?.
foo = "It was the year when they finally immanentized the Eschaton."
foo.byte_slice?(51, 8) # => "Eschaton"
Get a slice of the source at given range. This is analogous to
slice[range] without bounds checking.
Unsafe: Range should not exceed bounds.
foo = "It was the year when they finally immanentized the Eschaton."
unsafe do
foo.slice_unchecked(51..59) # => "Eschaton"
end