Scoop API

scoop:scoop.core:0.1.0

src/text_writer.scoop

Selected production source · src/text_writer.scoop

1/**
2 * A destination for Unicode text that does not prescribe storage or ownership.
3 */
4public interface TextWriter {
5 /**
6 * Writes the supplied text without adding a line terminator.
7 */
8 public fun write(text: String): Unit
9}
11/**
12 * An in-memory [TextWriter] backed by a [StringBuilder].
13 */
14public class StringWriter public constructor() : TextWriter, ToString {
15 private val builder: StringBuilder = StringBuilder()
17 /**
18 * Appends text to the in-memory result.
19 */
20 public override fun write(text: String): Unit {
21 builder.append(text)
22 }
24 /**
25 * Returns all text written so far.
26 */
27 public override fun toString(): String = builder.toString()