Giter Site home page Giter Site logo

Comments (4)

omus avatar omus commented on June 9, 2024

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.

from julia.

ssfrr avatar ssfrr commented on June 9, 2024

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.

from julia.

Seelengrab avatar Seelengrab commented on June 9, 2024

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 that esc has precedence here.

Do you have suggestions on how this could be made more explicit?

from julia.

ssfrr avatar ssfrr commented on June 9, 2024

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:

  1. it's only escaped if you're returning a string instead of writing to an IO stream
  2. if you want to prevent it from being escaped you need to remove it from 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.

from julia.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.