Issue #90 - modify write to print string escapes

This commit is contained in:
Justin Ethier 2016-08-08 18:33:17 -04:00
parent 64d39650fb
commit 99dce9d628

View file

@ -825,9 +825,29 @@ static object _Cyc_write(object x, FILE * port)
return quote_void; return quote_void;
} }
switch (type_of(x)) { switch (type_of(x)) {
case string_tag: case string_tag: {
fprintf(port, "\"%s\"", ((string_type *) x)->str); //fprintf(port, "\"%s\"", ((string_type *) x)->str);
char *s = string_str(x);
fputc('"', port);
while (*s){
switch(*s){
case '\a': fprintf(port, "\\a"); break;
case '\b': fprintf(port, "\\b"); break;
case '\f': fprintf(port, "\\f"); break;
case '\n': fprintf(port, "\\n"); break;
case '\r': fprintf(port, "\\r"); break;
case '\t': fprintf(port, "\\t"); break;
case '\v': fprintf(port, "\\v"); break;
case '\\': fprintf(port, "\\\\"); break;
default:
fputc(*s, port);
break; break;
}
s++;
}
fputc('"', port);
break;
}
// TODO: what about a list? contents should be displayed per (write) // TODO: what about a list? contents should be displayed per (write)
case vector_tag: case vector_tag:
fprintf(port, "#("); fprintf(port, "#(");