prettyprint: print unprintables by hex escaping.
parent
e00aaf4185
commit
f1e232c981
|
@ -96,7 +96,7 @@ M: f pprint* drop \ f pprint-word ;
|
||||||
[ effect>string ] [ effect-style ] bi styled-text ;
|
[ effect>string ] [ effect-style ] bi styled-text ;
|
||||||
|
|
||||||
! Strings
|
! Strings
|
||||||
: ch>ascii-escape ( ch -- str )
|
: ch>ascii-escape ( ch -- ch' ? )
|
||||||
H{
|
H{
|
||||||
{ CHAR: \a CHAR: a }
|
{ CHAR: \a CHAR: a }
|
||||||
{ CHAR: \e CHAR: e }
|
{ CHAR: \e CHAR: e }
|
||||||
|
@ -106,10 +106,12 @@ M: f pprint* drop \ f pprint-word ;
|
||||||
{ CHAR: \0 CHAR: 0 }
|
{ CHAR: \0 CHAR: 0 }
|
||||||
{ CHAR: \\ CHAR: \\ }
|
{ CHAR: \\ CHAR: \\ }
|
||||||
{ CHAR: \" CHAR: \" }
|
{ CHAR: \" CHAR: \" }
|
||||||
} at ;
|
} ?at ; inline
|
||||||
|
|
||||||
: unparse-ch ( ch -- )
|
: unparse-ch ( ch -- )
|
||||||
dup ch>ascii-escape [ "\\" % ] [ ] ?if , ;
|
ch>ascii-escape [ "\\" % , ] [
|
||||||
|
dup 32 < [ dup 16 < "\\x0" "\\x" ? % >hex % ] [ , ] if
|
||||||
|
] if ;
|
||||||
|
|
||||||
: do-string-limit ( str -- trimmed )
|
: do-string-limit ( str -- trimmed )
|
||||||
string-limit? get [
|
string-limit? get [
|
||||||
|
|
|
@ -40,6 +40,10 @@ unit-test
|
||||||
[ "\e" unparse ]
|
[ "\e" unparse ]
|
||||||
unit-test
|
unit-test
|
||||||
|
|
||||||
|
[ "\"\\x01\"" ]
|
||||||
|
[ 1 1string unparse ]
|
||||||
|
unit-test
|
||||||
|
|
||||||
[ "f" ] [ f unparse ] unit-test
|
[ "f" ] [ f unparse ] unit-test
|
||||||
[ "t" ] [ t unparse ] unit-test
|
[ "t" ] [ t unparse ] unit-test
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue