Am I using std.encoding correctly?
    Charles via Digitalmars-d-learn 
    digitalmars-d-learn at puremagic.com
       
    Sat Nov 14 06:55:45 PST 2015
    
    
  
I have some binary files that I'm reading. At compile time it's 
unknown what types I'm reading, and if they're strings, how it's 
encoded.
I'm doing something like this:
     Variant value;
     switch(type)
     {
         ...
         case Type.STRING:
             value = cast(dchar[])[];
             const(ubyte)[] buffer = raw[0 .. length];
             while (buffer.length > 0)
                 value ~= encodingScheme.decode(buffer);
             break;
         ...
     }
I know there's safeDecode, but I'm also fairly confident that all 
strings can decode safely, already, and if it isn't I'd want an 
exception thrown from it.
Is this correct usage? I guess I was a little surprised there was 
no decodeString that basically did this.
    
    
More information about the Digitalmars-d-learn
mailing list