lib: intro the StringOStream class
authorAlexis Laferrière <alexis.laf@xymus.net>
Sun, 3 Nov 2013 19:43:38 +0000 (14:43 -0500)
committerAlexis Laferrière <alexis.laf@xymus.net>
Fri, 7 Feb 2014 19:44:07 +0000 (14:44 -0500)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

lib/standard/stream.nit

index c4fe818..f161ebb 100644 (file)
@@ -296,3 +296,13 @@ redef interface Object
 
        private fun intern_poll( in_fds : Array[Int], out_fds : Array[Int] ) : nullable Int is extern import Array::length, Array::[], nullable Object as ( Int ), Int as nullable
 end
+
+# Stream to a String. Mainly used for compatibility with OStream type and tests.
+class StringOStream
+       super OStream
+
+       private var content = new Array[String]
+       redef fun to_s do return content.to_s
+       redef fun is_writable do return true
+       redef fun write(str) do content.add(str)
+end