Skip to content

Commit

Permalink
Proper graphme truncation for windows-style newline
Browse files Browse the repository at this point in the history
  • Loading branch information
alexrutar committed Nov 19, 2024
1 parent ef24853 commit 76ebd23
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions matcher/src/chars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,14 @@ pub(crate) enum CharClass {
pub fn graphemes(text: &str) -> impl Iterator<Item = char> + '_ {
#[cfg(feature = "unicode-segmentation")]
let res = text.graphemes(true).map(|grapheme| {
grapheme
.chars()
.next()
.expect("graphemes must be non-empty")
if grapheme == "\r\n" {
'\n'
} else {
grapheme
.chars()
.next()
.expect("graphemes must be non-empty")
}
});
#[cfg(not(feature = "unicode-segmentation"))]
let res = text.chars();
Expand Down

0 comments on commit 76ebd23

Please sign in to comment.