graphviz.dot: fix escaping logic
It used escape the escape char \, but it shouldn't do that because it leads to double escaping.db4
parent
3bf7e49e9f
commit
df93e4533d
|
@ -0,0 +1,21 @@
|
||||||
|
USING: graphviz.dot.private io.streams.string sequences tools.test ;
|
||||||
|
IN: graphviz.dot.tests
|
||||||
|
|
||||||
|
! Making sure strings are escaped properly
|
||||||
|
{
|
||||||
|
{
|
||||||
|
"\"BAH\" "
|
||||||
|
"\"LINE1\\nLINE2\" "
|
||||||
|
"\"\\lLINE1\\lLINE2\" "
|
||||||
|
"\"hum\\\"ho\\\"\" "
|
||||||
|
}
|
||||||
|
} [
|
||||||
|
{
|
||||||
|
"BAH"
|
||||||
|
"LINE1\\nLINE2"
|
||||||
|
"\\lLINE1\\lLINE2"
|
||||||
|
"hum\"ho\""
|
||||||
|
} [
|
||||||
|
[ dot. ] with-string-writer
|
||||||
|
] map
|
||||||
|
] unit-test
|
|
@ -1,8 +1,8 @@
|
||||||
! Copyright (C) 2012 Alex Vondrak.
|
! Copyright (C) 2012 Alex Vondrak.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: accessors classes classes.tuple combinators formatting graphviz
|
USING: accessors classes classes.tuple combinators formatting graphviz
|
||||||
graphviz.attributes io io.files kernel namespaces prettyprint.backend
|
graphviz.attributes io io.files kernel namespaces sequences splitting
|
||||||
sequences splitting strings words ;
|
strings words ;
|
||||||
IN: graphviz.dot
|
IN: graphviz.dot
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
@ -14,8 +14,12 @@ GENERIC: dot. ( obj -- )
|
||||||
! option in case there's a keyword clash, spaces in the ID,
|
! option in case there's a keyword clash, spaces in the ID,
|
||||||
! etc. This does mean that HTML labels aren't supported, but
|
! etc. This does mean that HTML labels aren't supported, but
|
||||||
! they don't seem to work using the Graphviz API anyway.
|
! they don't seem to work using the Graphviz API anyway.
|
||||||
|
!
|
||||||
|
! Special escaping logic is required here because of the \l escape
|
||||||
|
! sequence.
|
||||||
: quote-string ( str -- str' )
|
: quote-string ( str -- str' )
|
||||||
"\"" "\"" unparse-string "\0" split "" join ;
|
{ { "\"" "\\\"" } { "\0" "" } } [ first2 replace ] each
|
||||||
|
"\"" "\"" surround ;
|
||||||
|
|
||||||
M: string dot. quote-string "%s " printf ;
|
M: string dot. quote-string "%s " printf ;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue