Reading binary streams with decoding to Unicode

Nicholas Wilson iamthewilsonator at hotmail.com
Mon Oct 15 22:49:31 UTC 2018


On Monday, 15 October 2018 at 21:48:05 UTC, Vinay Sajip wrote:
> On Monday, 15 October 2018 at 19:56:22 UTC, Nicholas Wilson 
> wrote:
>>
>> import std.file : readText;
>> import std.uni : byCodePoint, byGrapheme;
>> // or import std.utf : byCodeUnit, byChar /*utf8*/, byWchar 
>> /*utf16*/, byDchar /*utf32*/, byUTF  /*utf8(?)*/;
>> string a = readText("foo");
>>
>> foreach(cp; a.byCodePoint)
>> {
>>     // do stuff with code point 'cp'
>> }
>
> Your example shows reading an entire file into memory (string a 
> = readText("foo")), then iterating over that. I know you can 
> iterate over a string; I'm interested in iterating over a 
> stream, which is perhaps read over a network or from another 
> I/O source, where you can't assume you have access to all of it 
> at once - just one Unicode character at a time.

Oh, sorry I missed that. Take a look at 
https://github.com/schveiguy/iopipe


More information about the Digitalmars-d-learn mailing list