[phobos] Transcoded text stdio
SHOO
zan77137 at nifty.com
Fri Aug 6 02:55:00 PDT 2010
I like #4.
I think we should start specifications development of the interface of
new D's I/O.
2010/8/6 Shin Fujishiro <rsinfu at gmail.com>:
> Hello,
>
> I'm trying to integrate codeset conversion facility to std.stdio.
> But how can it be done?
>
> Mixing transcoded and non-transcoded (UTF-8) I/O in the same File
> structure will mess up the source. I think separating UTF-8 based I/O
> and transcoded I/O is necessary.
>
> I could think of the following four ways.
>
> 1. Integrate everything in the File anyway.
>
> 2. Make the File to always perform conversion.
>
> 3. Create a distinct type for transcoded I/O.
> ----------
> shared TranscodedFile stdout;
> stdout.writeln("Hallå, Värld!");
> ----------
> # http://github.com/sinfu/misc/blob/master/stdio/test01.d
>
> 4. Simplify the File and define upper layer structures.
> ----------
> // File itself doesn't provide byLine etc.
> shared File stdout;
>
> // these 'ports' perform actual I/O for specific purposes
> shared UTF8TextIOPort stdoutUTF8;
> shared NativeTextIOPort stdoutText;
> shared BinaryIOPort stdoutBin;
>
> // wrap stdout with various 'I/O ports'
> stdoutUTF8 = UTF8TextIOPort(stdout);
> stdoutText = NativeTextIOPort(stdout);
> stdoutBin = BinaryIOPort(stdout);
>
> // write text in UTF-8
> stdoutUTF8.writeln("Hallå, Värld!");
>
> // write text in console encoding
> stdoutText.writeln("Hallå, Värld!");
>
> // free functions use stdoutText
> writeln("Hallå, Värld!");
> ----------
> # http://github.com/sinfu/misc/blob/master/stdio/test02.d
>
> ...
>
> I'm uncertain of which is the best. Perhaps there are more reasonable
> ways. What do you think? Any ideas?
>
>
> Thanks,
> Shin
> _______________________________________________
> phobos mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos
More information about the phobos
mailing list