-
Notifications
You must be signed in to change notification settings - Fork 45
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 configurable LineEnding #454
Conversation
@mgeisler , please let me know what do you think about the overall approach. |
Thanks so much for the PR, it looks really good! I've left a few comments, but overall I think this should work just fine. |
Yeah, thanks for listing this out. My preference would be for auto-detecting the input line ending in Of course, it could happen that there are no newlines in the input text: if so, then I think it's acceptable that the caller gets an |
Hey @edio, in #453 (comment) you mentioned that we could have a That could perhaps be nice! Normally, I would suggest that the callers should be explicit about this: I would expect editors and whatnot to know the encoding of the text they try to wrap. If the encoding is unknown, callers could always detect it using the code above. Because of this, I think we could defer adding this variant and just do the simple two-variant enum first. |
@mgeisler , got you, thanks! Not arguing, just want to explain my thinking: Rust's (also, ACK to all your comments, will get to the fixes ASAP, but next weekend may be busy for me, so I may get to it only next week. Sorry about the delay 🙏 ) |
227b0bf
to
cbc6f1e
Compare
Thanks for explaining!
Right, that's very clever! I see you implemented equal cleverness now in a very elegant iterator, which is awesome!
This is open source, there are no deadlines! We all work on this when we have time and energy 😃 Thank you for the great PR! |
Hey @edio, thanks for all the great updates on the PR. The build error on Rust 1.56 looks the same as what I had in another project: mgeisler/lipsum#84. I think you just need to be explicit with the type of the slice (for some reason which I don't understand). |
@mgeisler , thank you for the fix for the Rust 1.56 compatibility issue. It'd took me ages to figure that out. I believe I adressed all your requests for changes, but please do not hesitate to point to other problems if you can think of any. And thanks again for your time and help on this PR. |
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.
Thanks for all the updates!
Yeah, that was a weird case for me too 😄 |
fn refill_convert_crlf() { | ||
assert_eq!( | ||
refill("foo\nbar\n", Options::new(5).line_ending(LineEnding::CRLF)), | ||
"foo\r\nbar\n", |
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.
Do you think it's possible to make this return "foo\r\nbar\r\n"
in an easy way? I'm thinking that the problem might be in
let line_ending_pat: &[_] = &['\r', '\n'];
let trimmed = text.trim_end_matches(line_ending_pat);
which makes us eat the line ending (only to append it later without consideration for the detected line neding).
If it's not easy, then don't worry: what we have now is still great. We can fix this corner case later.
This also improves performance by ~20% in the unfill benchmark
Thanks for all the hard work on this! |
This is a quick demonstration of how configurable line ending support would look like #453 .
Immediately I see an issue with
unfill
which now requiresLineEnding
parameter, degrading experience for the clients who do not wish to deal with configurable line endings.Perhaps, we could have two fns:
unfill_with_endings(&str, LineEnding)
andunfill(&str) { unfill_with_endings(str, LineEnding::LF) }
Alternatives to consider
lines()
inunfill
(trimming trailing\r\n
could be implemented as discarding trailing empty lines)My gut feeling is that explicit control over the behavior is better (unicode defines multiple other options over the well-known
CR
andLF
), but I do not think this is a strong argument consideringlines()
only recognizes\n
and\r\n
.If the overall approach (or any of the alternatives) seems reasonable, I'll work towards finalizing this by providing tests, documentation, etc.. Let me know please.