| 1 |
(* |
| 2 |
* The basis seems to be missing a string (out)stream type. |
| 3 |
* This is it. |
| 4 |
* |
| 5 |
* -- Allen. |
| 6 |
*) |
| 7 |
structure StringOutStream :> STRING_OUTSTREAM = |
| 8 |
struct |
| 9 |
|
| 10 |
structure TextIO = TextIO |
| 11 |
structure TextPrimIO = TextPrimIO |
| 12 |
|
| 13 |
type streambuf = string list ref |
| 14 |
|
| 15 |
fun mkStreamBuf () = ref [] : streambuf |
| 16 |
fun getString (ref s) = String.concat(List.rev s) |
| 17 |
fun setString (r,s) = r := [s] |
| 18 |
|
| 19 |
fun openStringOut buffer = |
| 20 |
let fun writeVec sl = |
| 21 |
(buffer := CharVectorSlice.vector sl :: !buffer; |
| 22 |
CharVectorSlice.length sl) |
| 23 |
fun writeArr sl = |
| 24 |
(buffer := CharArraySlice.vector sl :: !buffer; |
| 25 |
CharArraySlice.length sl) |
| 26 |
val writer = |
| 27 |
TextPrimIO.WR |
| 28 |
{ name = "string stream", |
| 29 |
chunkSize = 512, |
| 30 |
writeVec = SOME writeVec, |
| 31 |
writeArr = SOME writeArr, |
| 32 |
writeVecNB = SOME (SOME o writeVec), |
| 33 |
writeArrNB = SOME (SOME o writeArr), |
| 34 |
block = NONE, |
| 35 |
canOutput = NONE, |
| 36 |
getPos = NONE, |
| 37 |
setPos = NONE, |
| 38 |
endPos = NONE, |
| 39 |
verifyPos = NONE, |
| 40 |
close = fn () => (), |
| 41 |
ioDesc = NONE |
| 42 |
} |
| 43 |
val outstream = TextIO.mkOutstream |
| 44 |
(TextIO.StreamIO.mkOutstream (writer,IO.NO_BUF)) |
| 45 |
in outstream |
| 46 |
end |
| 47 |
|
| 48 |
end |
| 49 |
|