File tree Expand file tree Collapse file tree 1 file changed +17
-7
lines changed
modules/analysis/src/service/render Expand file tree Collapse file tree 1 file changed +17
-7
lines changed Original file line number Diff line number Diff line change 1- use crate :: service:: Visitor ;
1+ use crate :: {
2+ model:: graph:: { self , Node } ,
3+ service:: Visitor ,
4+ } ;
5+ use std:: fmt:: Write ;
26use trustify_entity:: relationship:: Relationship ;
37
8+ /// Escape a string to be used as dot string value. The result
9+ /// must be placed within double quotes.
10+ ///
11+ /// Double quotes and backspace are prefixed with another backspace.
12+ ///
13+ /// Newlines are replaced with `\n`. CR, form-feed, and backspace are
14+ /// just dropped.
415fn escape ( id : & str ) -> String {
516 let mut escaped = String :: with_capacity ( id. len ( ) ) ;
617
718 for ch in id. chars ( ) {
819 match ch {
9- '"' => {
20+ '"' | '\\' => {
1021 escaped. push ( '\\' ) ;
1122 escaped. push ( ch) ;
1223 }
1324 '\n' => {
1425 escaped. push_str ( "\\ n" ) ;
1526 }
27+ '\r' | '\x08' | '\x0C' => {
28+ // just drop
29+ }
1630 _ => escaped. push ( ch) ,
1731 }
1832 }
1933
2034 escaped
2135}
2236
23- use crate :: model:: graph;
24- use crate :: model:: graph:: Node ;
25- use std:: fmt:: Write ;
26-
2737pub struct Renderer {
2838 data : String ,
2939}
@@ -104,9 +114,9 @@ impl Visitor for Renderer {
104114
105115#[ cfg( test) ]
106116mod test {
107-
108117 #[ test]
109118 fn escape ( ) {
110119 assert_eq ! ( super :: escape( "foo\" bar\n baz" ) , r#"foo\"bar\nbaz"# ) ;
120+ assert_eq ! ( super :: escape( "foo\\ \" bar\r baz" ) , r#"foo\\\"barbaz"# ) ;
111121 }
112122}
You can’t perform that action at this time.
0 commit comments