Checking, whether string contains only ascii.
jklm via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Feb 22 11:57:22 PST 2017
On Wednesday, 22 February 2017 at 19:26:15 UTC, berni wrote:
> In my program, I read a postscript file. Normal postscript
> files should only be composed of ascii characters, but one
> never knows what users give us. Therefore I'd like to make sure
> that the string the program read is only made up of ascii
> characters. This simplifies the code thereafter, because I then
> can assume, that codeunit==codepoint. Is there a simple way to
> do so?
>
> Here a sketch of my function:
>
>>void foo(string postscript)
>>{
>> // throw Exception, if postscript is not all ascii
>> // other stuff, assuming codeunit=codepoint
>>}
void foo(string postscript)
{
import std.ascii, astd.algorithm.ieration;
if (!args[0].filter!(a => !isASCII(a)).empty)
throw new Exception("bla");
}
More information about the Digitalmars-d-learn
mailing list