Skip to content

Commit

Permalink
Change \r detection much simpler.
Browse files Browse the repository at this point in the history
  • Loading branch information
wada314 committed Dec 23, 2018
1 parent 6a316e3 commit e37f468
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/comment.rs
Expand Up @@ -1304,13 +1304,7 @@ impl<'a> Iterator for LineClasses<'a> {
None => FullCodeCharKind::Normal,
};

while let Some((kind, mut c)) = self.base.next() {
// If \r\n newline appears, consume one more character.
// Then do the same process with the single \n case.
if c == '\r' && self.base.peek().map_or(false, |(_, c2)| *c2 == '\n') {
self.base.next();
c = '\n';
}
while let Some((kind, c)) = self.base.next() {
if c == '\n' {
self.kind = match (start_class, kind) {
(FullCodeCharKind::Normal, FullCodeCharKind::InString) => {
Expand All @@ -1327,6 +1321,11 @@ impl<'a> Iterator for LineClasses<'a> {
}
}

// Workaround for CRLF newline.
if line.ends_with('\r') {
line.pop();
}

Some((self.kind, line))
}
}
Expand Down

0 comments on commit e37f468

Please sign in to comment.