-
Notifications
You must be signed in to change notification settings - Fork 898
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
Not wrap strings at escape backslash #4524
Changes from 3 commits
5a371a0
bb8a8b9
e8eb088
c6e1673
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -225,7 +225,25 @@ fn not_whitespace_except_line_feed(g: &str) -> bool { | |
/// character is either a punctuation or a whitespace. | ||
/// FIXME(issue#3281): We must follow UAX#14 algorithm instead of this. | ||
fn break_string(max_width: usize, trim_end: bool, line_end: &str, input: &[&str]) -> SnippetState { | ||
let break_at = |index /* grapheme at index is included */| { | ||
let break_at = |index_in /* grapheme at index is included */| { | ||
// Ensure break is not after an escape '\' as it will "escape" the `\` that is added | ||
// for concatenating the two parts of the broken line. | ||
let index = if (input[index_in] as &str).ne("\\") { | ||
index_in | ||
} else { | ||
let index_offset = match input[0..index_in] | ||
.iter() | ||
.rposition(|grapheme| grapheme.ne(&"\\")) | ||
{ | ||
// There is a non-`\` to the left | ||
Some(non_backslash_index) => (index_in - non_backslash_index) % 2, | ||
// Only `\` to the left | ||
None => index_in % 2, | ||
}; | ||
// Make sure break is after even number (including zero) of `\` | ||
index_in - index_offset | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Admittedly another nit, but I think keeping There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK. submitted the change. |
||
|
||
// Take in any whitespaces to the left/right of `input[index]` while | ||
// preserving line feeds | ||
let index_minus_ws = input[0..=index] | ||
|
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.
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.
OK. Submitted the change (and I have still much to learn about rust, since I was not even aware that
!=
andne
are not the same).