Format text for output as plain text.
abstract class text formatter
implements output[text fragment]
extends text visitor[void]
implicit import idealruntimepatterns
protected static character NEWLINE : '\n'
protected static NEWLINE PATTERN : singleton pattern[character] • new(NEWLINE)
protected output[character] the output
protected string spaces
protected var nonnegative indent
protected var boolean first
protected text formatter(output[character] the output, string spaces)
this • the output = the output
this • spaces = spaces
indent = 0
override void write(text fragment fragment)
process(fragment)
override void write all(readonly list[text fragment] fragments)
for (fragment : fragments)
process(fragment)
override void sync()
override void close()
override abstract void process string(string s)
override abstract void process special(special text t)
protected void write string(string the string)
var nonnegative index : 0
while index < the stringsize
if first
newline match : NEWLINE PATTERNfind first(the string, index)
if newline match is null
do write string(the stringskip(index))
break
else
newline index : newline matchbegin
do write string(the stringslice(index, newline index))
index = newline matchend
protected void do write indent()
for var nonnegative i : 0; i < indent; i += 1
protected void do write string(readonly list[character] s)