Skip to content

Commit d5d3a99

Browse files
committed
Remove dead code - these checks already performed by a parser
(review with with whitespace ignored mode)
1 parent 0302010 commit d5d3a99

File tree

1 file changed

+16
-31
lines changed

1 file changed

+16
-31
lines changed

src/reader/state.rs

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
use encoding_rs::{UTF_16BE, UTF_16LE, UTF_8};
33

44
use crate::encoding::Decoder;
5-
use crate::errors::{Error, IllFormedError, Result, SyntaxError};
5+
use crate::errors::{Error, IllFormedError, Result};
66
use crate::events::{BytesCData, BytesDecl, BytesEnd, BytesStart, BytesText, Event};
77
use crate::parser::{FeedResult, Parser};
88
#[cfg(feature = "encoding")]
@@ -364,39 +364,24 @@ impl ReaderState {
364364
debug_assert!(content.starts_with(b"<?"), "{:?}", Bytes(content));
365365
debug_assert!(content.ends_with(b"?>"), "{:?}", Bytes(content));
366366

367-
let buf = &content[1..content.len() - 1];
368-
debug_assert!(buf.len() > 0);
369-
debug_assert_eq!(buf[0], b'?');
370-
371-
let len = buf.len();
372-
// We accept at least <??>
373-
// ~~ - len = 2
374-
if len > 1 && buf[len - 1] == b'?' {
375-
// Cut of `?` and `?` from start and end
376-
let content = &buf[1..len - 1];
377-
let len = content.len();
378-
379-
if content.starts_with(b"xml") && (len == 3 || is_whitespace(content[3])) {
380-
let event = BytesDecl::from_start(BytesStart::wrap(content, 3));
381-
382-
// Try getting encoding from the declaration event
383-
#[cfg(feature = "encoding")]
384-
if self.encoding.can_be_refined() {
385-
if let Some(encoding) = event.encoder() {
386-
self.encoding = EncodingRef::XmlDetected(encoding);
387-
}
388-
}
367+
// Cut of `<?` and `?>` from start and end
368+
let content = &content[2..content.len() - 2];
369+
let len = content.len();
370+
371+
if content.starts_with(b"xml") && (len == 3 || is_whitespace(content[3])) {
372+
let event = BytesDecl::from_start(BytesStart::wrap(content, 3));
389373

390-
Ok(Event::Decl(event))
391-
} else {
392-
Ok(Event::PI(BytesText::wrap(content, self.decoder())))
374+
// Try getting encoding from the declaration event
375+
#[cfg(feature = "encoding")]
376+
if self.encoding.can_be_refined() {
377+
if let Some(encoding) = event.encoder() {
378+
self.encoding = EncodingRef::XmlDetected(encoding);
379+
}
393380
}
381+
382+
Ok(Event::Decl(event))
394383
} else {
395-
// <?....EOF
396-
// ^^^^^ - `buf` does not contains `<`, but we want to report error at `<`,
397-
// so we move offset to it (-2 for `<` and `>`)
398-
self.last_error_offset = self.offset - len - 2;
399-
Err(Error::Syntax(SyntaxError::UnclosedPIOrXmlDecl))
384+
Ok(Event::PI(BytesText::wrap(content, self.decoder())))
400385
}
401386
}
402387
FeedResult::EmitEmptyTag(_) => {

0 commit comments

Comments
 (0)