diff options
author | Arun Isaac | 2021-12-13 17:59:03 +0530 |
---|---|---|
committer | Arun Isaac | 2021-12-13 18:06:11 +0530 |
commit | 1e2c9f9893ee2af5a2aa72f512742d101da8cf6a (patch) | |
tree | d62fa7533c32fdd94b269a8f827b1f64916a951e | |
parent | 64ed9fb4581b290c6c64152e577ee166ff1d4dd7 (diff) | |
download | ccwl-1e2c9f9893ee2af5a2aa72f512742d101da8cf6a.tar.gz ccwl-1e2c9f9893ee2af5a2aa72f512742d101da8cf6a.tar.lz ccwl-1e2c9f9893ee2af5a2aa72f512742d101da8cf6a.zip |
ccwl: Organize serialize into a generic function.
* ccwl/graphviz.scm (serialize): Organize into a generic function that
dispatches on input type.
-rw-r--r-- | ccwl/graphviz.scm | 35 |
1 files changed, 17 insertions, 18 deletions
diff --git a/ccwl/graphviz.scm b/ccwl/graphviz.scm index a3f4036..a505530 100644 --- a/ccwl/graphviz.scm +++ b/ccwl/graphviz.scm @@ -121,24 +121,23 @@ language." (define (serialize object) "Serialize OBJECT according to graphviz dot syntax. OBJECT may a symbol, a string, or a <html-string> object." - (let ((str (cond - ((symbol? object) (symbol->string object)) - ((string? object) object) - ((html-string? object) (html-string-underlying object)) - (else (error "Unknown object type to serialize to graphviz dot:" object))))) - (cond - ;; Surround HTML strings in <>, and don't escape. - ((html-string? object) - (format "<~a>" str)) - ;; Don't quote safe strings. - ((string-every (char-set-union (char-set-intersection char-set:letter+digit - char-set:ascii) - (char-set #\_)) - str) - str) - ;; Quote strings with unsafe characters. - (else - (format "\"~a\"" (string-replace-substring str "\"" "\\\"")))))) + (cond + ((symbol? object) + (serialize (symbol->string object))) + ;; Surround HTML strings in <>, and don't escape. + ((html-string? object) + (format "<~a>" (html-string-underlying object))) + ;; Don't quote safe strings. + ((and (string? object) + (string-every (char-set-union (char-set-intersection char-set:letter+digit + char-set:ascii) + (char-set #\_)) + object)) + object) + ;; Quote strings with unsafe characters. + ((string? object) + (format "\"~a\"" (string-replace-substring object "\"" "\\\""))) + (else (error "Unknown object type to serialize to graphviz dot:" object)))) (define* (graph->dot graph #:optional (port (current-output-port)) (level 0)) "Render GRAPH, a <graph> object, in the graphviz dot syntax to |