How to use InputRange! (Dchar) with Stdin in D 2.0?

I am trying to write generic code that can lex any character stream ( dchar s) anywhere ... whether from a file or from stdin to another file or stdout .

How to do it?

It seems that stdin and stdout painful for use with InputRange and OutputRange (since I have to wrap them every time), and I cannot use std.stdio.Stream because it gives me bytes, not strings ... and I can’t find any adapter to convert from one to another easily.

So efficiently, I cannot find a good way to use stdin / stdout in my programs.

Is there something for example. like .NET TextReader , which can abstractly read text as InputRange!dchar , regardless of whether its input is a string, console, or file?

+4
source share
1 answer

A native function that accepts an input dchar range:

 void func(Range)(Range input) if(isInputRange!Range && is(ElementType!Range == dchar)) {} 

However, you must have an input range that gets its input from stdin. They talk about the need to redo stdio / streaming, which has not yet been done. There is an undocumented dchar range for stdin.

+2
source

All Articles