-
Notifications
You must be signed in to change notification settings - Fork 15
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 support for operating on byte strings #15
Conversation
This doesn’t change the MSRV. I’m also reasonably confident that this doesn’t change any existing behavior. |
Oh, oops. I didn’t actually deal with I’ll deal with that stuff tomorrow. |
Ok. This should be basically functional now. It passes Still to do:
|
I added a commit to implement Using |
Ok, documentation, README and CHANGELOG updated! Ping @comex, let me know what you think. I generally tried to match your style, but I imagine I diverged a bit, especially in the documentation. Happy to change things. MSRV remains 1.36.0. |
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.
You can get rid of quote_internal
and the Option
wrapping by implementing crate::quote
like this:
/// Given a single word, return a string suitable to encode it as a shell argument.
pub fn quote(in_str: &str) -> Cow<str> {
match bytes::quote(in_str.as_bytes()) {
Cow::Borrowed(out) => {
// Safety: bytes::quote() was given valid UTF-8, so it will
// always return valid UTF-8.
unsafe { core::str::from_utf8_unchecked(out) }.into()
}
Cow::Owned(out) => {
// Safety: bytes::quote() was given valid UTF-8, so it will
// always return valid UTF-8.
unsafe { String::from_utf8_unchecked(out) }.into()
}
}
}
Or am I missing another reason it's done this way?
That is nicer. In other projects I don’t use the |
This adds a `bytes` submodule for operating on byte strings that might contain invalid UTF-8. Where possible I have switched the functions that operate on `str` to use the `bytes` functions internally to avoid duplicating code and eliminate the potential for differing behavior between the two functions. It includes trivial tests that confirm that the `bytes` version of functions actually work on invalid UTF-8. Fixes #12
Thank you for your contribution! This has now been released as version 1.2.0. |
This addsThis adds aShlex::new_bytes()
,quote_bytes()
, andjoin_bytes()
.bytes
submodule for operating on byte strings that might contain invalid UTF-8. Where possible I have switched the functions that operate onstr
to use the_bytes
functions internally to avoid duplicating code and eliminate the potential for differing behavior between the two functions.It includes trivial tests that confirm that the
bytes
version of functions actually work on invalid UTF-8.I have not updated the documentation; this is just a first draft to solicit feedback.Fixes #12
Update: Fixed some problems I mentioned in the comments. Updated the description above; italics are new.