Am I using std.encoding correctly?

anonymous via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Nov 14 11:23:53 PST 2015


On 14.11.2015 15:55, Charles wrote:
> 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.

Documentation [1] says "The input to this function MUST be validly 
encoded." It says nothing about an Exception being thrown when the input 
is invalid. I'd interpret that "MUST" as "there is no defined behavior 
for bad input".

So if there's a chance that the input is invalid, don't use plain `decode`.

> Is this correct usage? I guess I was a little surprised there was no
> decodeString that basically did this.

I can't find a simpler way to decode a whole string either. Would be a 
useful addition. Make it a range. Or if we're both just missing it, then 
it should probably be documented more prominently.


[1] http://dlang.org/phobos/std_encoding.html#.EncodingScheme.decode


More information about the Digitalmars-d-learn mailing list