aboutsummaryrefslogtreecommitdiff
path: root/src/machine.rs
diff options
context:
space:
mode:
authorMartin Fischer <martin@push-f.com>2023-09-02 12:27:14 +0200
committerMartin Fischer <martin@push-f.com>2023-09-03 23:00:05 +0200
commite993f19c2b8ef00b32f17f9ed32306f3ceb21bc3 (patch)
tree4992456f36e6d012b4cc54a69811ec321cc4550c /src/machine.rs
parentc8a8bcb95b725d91a7c4b7bc7623171f2a04fc67 (diff)
fix!: make comment data spans encoding-independent
Diffstat (limited to 'src/machine.rs')
-rw-r--r--src/machine.rs27
1 files changed, 16 insertions, 11 deletions
diff --git a/src/machine.rs b/src/machine.rs
index f00af0a..26e1652 100644
--- a/src/machine.rs
+++ b/src/machine.rs
@@ -950,11 +950,11 @@ where
State::BogusComment => match slf.read_char()? {
Some('>') => {
slf.state = State::Data;
- slf.emitter.emit_current_comment(slf.reader.position());
+ slf.emitter.emit_current_comment(slf.position_before_match);
Ok(ControlToken::Continue)
}
None => {
- slf.emitter.emit_current_comment(slf.reader.position());
+ slf.emitter.emit_current_comment(slf.position_before_match);
Ok(ControlToken::Eof)
}
Some('\0') => {
@@ -994,7 +994,7 @@ where
Some('>') => {
slf.emit_error(Error::AbruptClosingOfEmptyComment);
slf.state = State::Data;
- slf.emitter.emit_current_comment(slf.reader.position());
+ slf.emitter.emit_current_comment(slf.position_before_match);
Ok(ControlToken::Continue)
}
c => {
@@ -1008,15 +1008,19 @@ where
slf.state = State::CommentEnd;
Ok(ControlToken::Continue)
}
- Some('>') => {
+ Some(c @ '>') => {
slf.emit_error(Error::AbruptClosingOfEmptyComment);
slf.state = State::Data;
- slf.emitter.emit_current_comment(slf.reader.position());
+ slf.emitter.emit_current_comment(
+ slf.position_before_match - slf.reader.len_of_char_in_current_encoding(c),
+ );
Ok(ControlToken::Continue)
}
None => {
slf.emit_error(Error::EofInComment);
- slf.emitter.emit_current_comment(slf.reader.position());
+ slf.emitter.emit_current_comment(
+ slf.position_before_match - slf.reader.len_of_char_in_current_encoding('-'),
+ );
Ok(ControlToken::Eof)
}
c @ Some(_) => {
@@ -1033,6 +1037,7 @@ where
Ok(ControlToken::Continue)
}
Some('-') => {
+ slf.some_offset = slf.position_before_match;
slf.state = State::CommentEndDash;
Ok(ControlToken::Continue)
}
@@ -1109,7 +1114,7 @@ where
}
None => {
slf.emit_error(Error::EofInComment);
- slf.emitter.emit_current_comment(slf.reader.position());
+ slf.emitter.emit_current_comment(slf.some_offset);
Ok(ControlToken::Eof)
}
c => {
@@ -1122,7 +1127,7 @@ where
State::CommentEnd => match slf.read_char()? {
Some('>') => {
slf.state = State::Data;
- slf.emitter.emit_current_comment(slf.reader.position());
+ slf.emitter.emit_current_comment(slf.some_offset);
Ok(ControlToken::Continue)
}
Some('!') => {
@@ -1135,7 +1140,7 @@ where
}
None => {
slf.emit_error(Error::EofInComment);
- slf.emitter.emit_current_comment(slf.reader.position());
+ slf.emitter.emit_current_comment(slf.some_offset);
Ok(ControlToken::Eof)
}
c @ Some(_) => {
@@ -1157,12 +1162,12 @@ where
Some('>') => {
slf.emit_error(Error::IncorrectlyClosedComment);
slf.state = State::Data;
- slf.emitter.emit_current_comment(slf.reader.position());
+ slf.emitter.emit_current_comment(slf.some_offset);
Ok(ControlToken::Continue)
}
None => {
slf.emit_error(Error::EofInComment);
- slf.emitter.emit_current_comment(slf.reader.position());
+ slf.emitter.emit_current_comment(slf.some_offset);
Ok(ControlToken::Eof)
}
c @ Some(_) => {