Copy a subset of self starting at from and of count bytes

var b = "abcd".to_bytes
assert b.slice(1, 2).hexdigest == "6263"
assert b.slice(-1, 2).hexdigest == "61"
assert b.slice(1, 0).hexdigest == ""
assert b.slice(2, 5).hexdigest == "6364"

Property definitions

core $ Bytes :: slice
	# Copy a subset of `self` starting at `from` and of `count` bytes
	#
	#     var b = "abcd".to_bytes
	#     assert b.slice(1, 2).hexdigest == "6263"
	#     assert b.slice(-1, 2).hexdigest == "61"
	#     assert b.slice(1, 0).hexdigest == ""
	#     assert b.slice(2, 5).hexdigest == "6364"
	fun slice(from, count: Int): Bytes do
		if count <= 0 then return new Bytes.empty

		if from < 0 then
			count += from
			if count < 0 then count = 0
			from = 0
		end

		if (count + from) > length then count = length - from
		if count <= 0 then return new Bytes.empty

		var ret = new Bytes.with_capacity(count)

		ret.append_ns(items.fast_cstring(from), count)
		return ret
	end
lib/core/bytes.nit:310,2--333,4