eliminate cast
Janice Caron
caron800 at googlemail.com
Thu May 15 12:40:06 PDT 2008
On 14/05/2008, Dee Girl <deegirl at noreply.com> wrote:
> O.K. but let say we want to check for invalid file (binary and not ascii). How can I do it? Thank you, Dee Girl
First off, char and string mean UTF-8, not ASCII. So by casting to
string, you are saying "I know this is UTF-8".
There is a way to say "This is ASCII", which is to cast to AsciiString
instead of to string. (AsciiString is defined in std.encoding).
There are currently two ways to validate. There's the old way:
std.utf.validate(), which throws an exception if the validation fails.
That will work for UTF-8, but it won't work for ASCII.
Then there's the new way: std.encoding.isValid(), which returns bool
if validation fails. That one works for ASCII too, providing your data
has type AsciiString instead of string.
Yes, there's currently duplicate functionality in Phobos, but std.utf
will eventally be deprecated in favor of std.encoding.
More information about the Digitalmars-d
mailing list