Debian Codegraph @

lib/mlrisc-lib/MLRISC/library/line-break.sml

raw
1 signature LINE_BREAK =
2 sig
3 val lineBreak : int -> string -> string
4 end
5
6 structure LineBreak : LINE_BREAK =
7 struct
8 fun lineBreak maxChars text =
9 let fun loop([],_,text) = String.concat(rev text)
10 | loop(s::ss,n,text) =
11 let val m = String.size s + 1
12 val n' = m+n
13 in if n' > maxChars
14 then loop(ss, m, s::" "::"\n"::text)
15 else loop(ss, n', s::" "::text)
16 end
17 val toks = String.fields (fn c => c = #" ") text
18 in loop(toks, 0, []) end
19 end