string to thread

Jonathan M Davis jmdavisProg at gmx.com
Sun Sep 9 03:36:28 PDT 2012


On Sunday, September 09, 2012 12:21:59 monarch_dodra wrote:
> Hum, parse. Looks useful. No need to create a temp stream like in
> C++ then. Good. Thanks for the info.
> 
> That said, is the "abstraction" itself available? Say *someone*
> wrote an xml parser, and the public interface expects to operate
> on a "File". Now, supposing I don't have a file, but all I have
> is a string, is it possible for someone pass that string the the
> function?

So, your asking if you can pass a string to a function which requires a file? 
Is that what you're asking? I don't see why that would work, given that the 
function expects a file. So, I must be misunderstanding something...

But one of the key design philosophies in Phobos is to use range-based APIs 
for just about everything. So, we wouldn't have an XML parser which operated 
on a file. It would operate on a range, and if you wanted to operate on a file, 
you'd get a range over the file and pass it in rather than the file. That's 
actually one key area that std.io should improve over std.stdio once Steven 
finally finishes it (since right now, it's kind of hard to have a good range 
interface on a file - you've can operate on it as a range of lines or chunks or 
whatnot but not as a range of characters or bytes without creating some sort 
of wrapper). But by using ranges everywhere, it becomes a lot like the *nix 
command-line where you can take the output of any program and pipe it as input 
to another program, allowing you to chain programs and mix and match them, but 
it's with ranges and functions rather than pipes and programs.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list