Reading binary streams with decoding to Unicode
    Vinay Sajip 
    vinay_sajip at yahoo.co.uk
       
    Mon Oct 15 21:48:05 UTC 2018
    
    
  
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.
    
    
More information about the Digitalmars-d-learn
mailing list