atomo-0.2.1: prelude/string.atomo
{ @empty-string describe-error := "string is empty"
(s: String) indent: (n: Integer) :=
s lines (map: { l | $ (repeat: n) .. l }) (join: "\n")
(s: String) word-wrap: (length: Integer) :=
s lines
(map: { l | (l take-while: @space?) .. (wrap-line: l to: length) })
unlines
wrap-line: l to: length :=
{ words = l words
line-length = 0
ok-words =
words take-while:
{ w |
line-length = line-length + 1 + w length
line-length < length
} in-context
[ ok-words unwords
words (drop: ok-words length) unwords word-wrap: length
] unlines strip-end
} call
} call