-
Notifications
You must be signed in to change notification settings - Fork 11
Move JLD2.jl dependency to a package extension #50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
The latter will lead to invalidations when JLD2 is loaded
ext/MetaGraphsJLD2Ext.jl
Outdated
| # escaping unescaped quotation marks | ||
| # i.e. replacing `"`` with `\"` while leaving `\"` as is | ||
| escape_quotes(s::AbstractString) = replace(s, r"([^\\])\"" => s"\1\\\\\"") | ||
|
|
||
| # According to the DOT language specification https://graphviz.org/doc/info/lang.html | ||
| # we can quote everyhthing that's not an XML/HTML literal | ||
| function quote_prop(p::AbstractString) | ||
| if occursin(r"<+.*>+$", p) | ||
| # The label is an HTML string, no additional quotes here. | ||
| return p | ||
| else | ||
| return "\"" * escape_quotes(p) * "\"" | ||
| end | ||
| end | ||
| # if the property value is _not_ a string it cannot be XML/HTML literal, so just put it in quotes | ||
| quote_prop(p::Any) = "\"" * escape_quotes(string(p)) * "\"" | ||
| # NOTE: down there I only quote property _values_. DOT allows quoting property _names_ too | ||
| # I don't do that as long as names are Symbols and can't have spaces and commas and stuff. | ||
| # That will break if someone uses a DOT keyword as a property name, as they must be quoted. | ||
|
|
||
| function MetaGraphs.savedot(io::IO, g::AbstractMetaGraph) | ||
| if is_directed(g) | ||
| write(io, "digraph G {\n") | ||
| dash = "->" | ||
| else | ||
| write(io, "graph G {\n") | ||
| dash = "--" | ||
| end | ||
|
|
||
| for p in props(g) | ||
| write(io, "$(p[1])=$(quote_prop(p[2]));\n") | ||
| end | ||
|
|
||
| for v in vertices(g) | ||
| write(io, "$v") | ||
| if length(props(g, v)) > 0 | ||
| write(io, " [ ") | ||
|
|
||
| for p in props(g, v) | ||
| write(io, "$(p[1])=$(quote_prop(p[2])), ") | ||
| end | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these functions in any way connected to the JLD2 backend?
I think these should stay in the main package.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point, they don't look like they are
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved the dot format stuff back to the package. Note that the savedot function is neither tested, documented, or exported.
No description provided.