[phobos] Transcoded text stdio

Shin Fujishiro rsinfu at gmail.com
Fri Sep 17 10:04:31 PDT 2010


Thank you for picking up the topic!

Andrei Alexandrescu <andrei at erdani.com> wrote:
> Regarding transcoding output, please let me know I understand the 
> problem correctly: under Windows (and possibly under other OSs under 
> certain configurations) the console is not UTF and cannot be reasonably 
> forced to be UTF.

Yes.  Neither input or output isn't UTF under Windows.

> I think for such situations, the classic Decorator-based design with 
> stacked interfaces works well: you have a TranscodingStream wrapping a 
> NativeStream or a UTFStream or whatever.
> 
> The streaming interface question comes again, i.e. what is the interface 
> that allows such stacking with minimal cost in efficiency?

The cost is minimal when the transcoder has direct access to both I/O
device and buffer.  I mean, there would be no redundant copy involved:

    ubyte[N] tmp = void;
    convert(buffer, tmp);
    device_write(tmp);

So, the best layer for doing converted (or filtered) I/O is the stream
buffer.  But I feels like it's not quite right... buffering layer might
be too 'low level' for character code conversion.


Shin


More information about the phobos mailing list