ANSI - output with phobos

Derek Parnell derek at nomail.afraid.org
Tue Apr 3 17:30:45 PDT 2007


On Tue, 03 Apr 2007 20:16:06 -0400, me wrote:

> for(char c = 0; c < c.max; c++)
>     writefln(c);
> 
> In a not too distant past the above code could produce the entire ANSI table, however this is not the case today. Today it peters out at 127 and any code beyond that cannot be desplayed. The error message produced is:
> 
>   Error: 4invalid UTF-8 sequence
> 
> Please provide some guidance on how to accomplish this in present D.
> 

Characters whose numeric representation is above 127 and less than 256, are
not UTF-8 characters and the function 'writefln' expects 'char' values to
be UTF-8. So, to do what you want, you must either not use writefln or not
use 'char' types.

import std.stdio;
void main()
{

 for(ubyte c = 0; c < c.max; c++)
 {
     if (c <= 127) writef("'%s' ", cast(char)c);
     writefln(c);
 }
}

-- 
Derek
(skype: derek.j.parnell)
Melbourne, Australia
"Justice for David Hicks!"
4/04/2007 10:22:49 AM


More information about the Digitalmars-d-learn mailing list