ln
chars.This variant ensures that only the first element might be smaller than ln
var s = "abcdefghijklmnopqrstuvwxyz"
assert s.pack_r(4) == ["ab","cdef","ghij","klmn","opqr","stuv","wxyz"]
# Packs the content of a string in packs of `ln` chars.
# This variant ensures that only the first element might be smaller than `ln`
#
# ~~~
# var s = "abcdefghijklmnopqrstuvwxyz"
# assert s.pack_r(4) == ["ab","cdef","ghij","klmn","opqr","stuv","wxyz"]
# ~~~
fun pack_r(ln: Int): Array[Text] do
var st = length
var retarr = new Array[Text].with_capacity(length / ln + length % ln)
while st >= 0 do
retarr.add(substring(st - ln, ln))
st -= ln
end
return retarr.reversed
end
lib/core/text/abstract_text.nit:1254,2--1269,4