core/stream: StringWriter uses a Buffer internally
authorJean Privat <jean@pryen.org>
Thu, 16 Feb 2017 14:40:25 +0000 (09:40 -0500)
committerJean Privat <jean@pryen.org>
Thu, 16 Feb 2017 14:40:25 +0000 (09:40 -0500)
Signed-off-by: Jean Privat <jean@pryen.org>

lib/core/stream.nit

index 217e9c8..6fbc63c 100644 (file)
@@ -668,18 +668,24 @@ end
 class StringWriter
        super Writer
 
-       private var content = new Array[String]
-       redef fun to_s do return content.plain_to_s
+       private var content = new Buffer
+       redef fun to_s do return content.to_s
        redef fun is_writable do return not closed
 
        redef fun write_bytes(b) do
-               content.add(b.to_s)
+               content.append(b.to_s)
        end
 
        redef fun write(str)
        do
                assert not closed
-               content.add(str.to_s)
+               content.append(str)
+       end
+
+       redef fun write_char(c)
+       do
+               assert not closed
+               content.add(c)
        end
 
        # Is the stream closed?