(*  Title:      Pure/General/buffer.ML
    ID:         $Id: buffer.ML,v 1.7 2005/08/16 11:42:33 wenzelm Exp $
    Author:     Markus Wenzel, TU Muenchen

Simple string buffers.
*)

signature BUFFER =
sig
  type T
  val empty: T
  val add: string -> T -> T
  val content: T -> string
  val write: Path.T -> T -> unit
end;

structure Buffer: BUFFER =
struct

datatype T = Buffer of string list;

val empty = Buffer [];

fun add "" buf = buf
  | add x (Buffer xs) = Buffer (x :: xs);

fun content (Buffer xs) = implode (rev xs);

fun write path (Buffer xs) = File.write_list path (rev xs);

end;
