ln
chars.This variant ensures that only the last element might be smaller than ln
var s = "abcdefghijklmnopqrstuvwxyz"
assert s.pack_l(4) == ["abcd","efgh","ijkl","mnop","qrst","uvwx","yz"]
# Packs the content of a string in packs of `ln` chars.
# This variant ensures that only the last element might be smaller than `ln`
#
# ~~~
# var s = "abcdefghijklmnopqrstuvwxyz"
# assert s.pack_l(4) == ["abcd","efgh","ijkl","mnop","qrst","uvwx","yz"]
# ~~~
fun pack_l(ln: Int): Array[Text] do
var st = 0
var retarr = new Array[Text].with_capacity(length / ln + length % ln)
while st < length do
retarr.add(substring(st, ln))
st += ln
end
return retarr
end
lib/core/text/abstract_text.nit:1237,2--1252,4