Skip to content
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

Add \0 and \x{xx} to supported escapes #15

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

digitalrane
Copy link

Hello,

I needed to support some older data files that used \0 and \x{xx} instead of \u{00} and \u{xx} respectively, so I made this small change to snailquote. I've tested it and it works well. Thank you for this crate!

@euank
Copy link
Owner

euank commented Nov 6, 2022

Sorry for the very slow response here! I went back and forth a bit on whether I wanted to merge this, and then it sorta slipped my mind to actually type out my thoughts 😅

The main reason I'm unsure about accepting this is mostly about the precedent and intent of this library.

The goal of snailquote is to give a human readable and editable representation of an arbitrary string, and then to be able to re-parse the text it produced. (and also parse os-release values I guess. maybe that already set the bad precedent oops).

It sounds like you're using it to parse some other data format which it happens to be almost compatible with. It's neat that it worked for that with only this small tweak, but that's outside the intended scope of the library.

As for the actual change here:

I do think adding \0 is a good change in-line with the original intent of snailquote. I think we'd also want to produce \0 when escaping if it were added since it's more readable, and escape prefers the more readable escape sequences over \u.

I think adding \x in addition to \u is a less clearly beneficial. escape always produces the \u variant, and it doesn't seem to me like something a user editing some output from escape would expect to be supported, so it seems less in-line with snailquote's intent than \0.

There's arbitrarily many ANSI-c-string-like formats this could parse, but for the intent of letting users edit text, I think it's a better to keep a minimal set of escapes/formats.

So, where does that leave us?

You're, of course, welcome to advocate for this change. After going back and forth a bit, I think I'm leaning towards keeping the supported syntax simpler by not taking it, but I'm not totally convinced.

Forking or copying+modifying the code to specialize to the format you're dealing with is also, of course, an option.

Do you have any thoughts/opinions here?

Oh, and I forgot to say, thanks for the PR and dropping by!
And also, I'm curious what format it is you're dealing with, if you do want to share :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants