Open ssfrr opened 1 month ago
This is because escape_string(s; keep=('"',))
is actually escape_string(s, ('"',); keep=('"',))
and the esc
argument takes precedence over keep
. You can work around this via:
julia> escape_string(s, (); keep=('"',))
"\""
This does seem to be something that should be at a minimum fixed in the documentation.
ah, I see, thanks. That was not what I expected, as I figured the 2nd positional arg represented the set of additional characters that would be escaped, on top of the default ones.
This does seem to be something that should be at a minimum fixed in the documentation.
It is mentioned in the docstring:
The optional
esc
argument specifies any additional characters that should also be escaped by a prepending backslash ("
is also escaped by default in the first form).The argument
keep
specifies a collection of characters which are to be kept as they are. Notice thatesc
has precedence here.
Do you have suggestions on how this could be made more explicit?
Ah, thanks, I guess I missed or misunderstood that part of the docstring.
I think that part that's not super clear in the docstring is that \n
and "
are both escaped by default, but are handled differently.
\n
and friends are sort of "implicit" defaults, and you can prevent them from being escaped by adding them to keep
. "
is different in that:
esc
rather than adding it to keep
(@omus it turns out you don't actually need to add it to keep
at all).Can anyone shed some light as to why it's implemented this way? I'm happy to take a crack at clarifying the docstring, but I think I'd want to include some extra context for the why.
@omus it turns out you don't actually need to add it to keep at all
True. I thought it was clearer to include "
in keep
in addition to having to exclude it from esc
.
I may be mis-understanding how this is supposed to work, but it doesn't seem that I can prevent
escape_string
from escaping double-quote characters.Note it works as I'd expect for
\n
:From nightly as of May 17: