Skip to content

Commit bbc090b

Browse files
committed
Added as_static_str() method to lexer tokens
1 parent 5fd0b44 commit bbc090b

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/reader/lexer.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,28 @@ impl fmt::Show for Token {
8080
}
8181

8282
impl Token {
83+
pub fn as_static_str(&self) -> Option<&'static str> {
84+
match *self {
85+
OpeningTagStart => Some("<"),
86+
ProcessingInstructionStart => Some("<?"),
87+
DoctypeStart => Some("<!DOCTYPE"),
88+
ClosingTagStart => Some("</"),
89+
CommentStart => Some("<!--"),
90+
CDataStart => Some("<![CDATA["),
91+
TagEnd => Some(">"),
92+
EmptyTagEnd => Some("/>"),
93+
ProcessingInstructionEnd => Some("?>"),
94+
CommentEnd => Some("-->"),
95+
CDataEnd => Some("]]>"),
96+
ReferenceStart => Some("&"),
97+
ReferenceEnd => Some(";"),
98+
EqualsSign => Some("="),
99+
SingleQuote => Some("'"),
100+
DoubleQuote => Some("\""),
101+
_ => None
102+
}
103+
}
104+
83105
/// Returns `true` if this token contains data that can be interpreted
84106
/// as a part of the text. Surprisingly, this also means '>' and '=' and '"' and "'".
85107
#[inline]

src/reader/parser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ impl PullParser {
441441

442442
ReferenceEnd => { // Semi-colon in a text outside an entity
443443
self.inside_whitespace = false;
444-
self.append_str_continue(";")
444+
self.append_str_continue(ReferenceEnd.as_static_str().unwrap())
445445
}
446446

447447
CommentStart if self.config.coalesce_characters && self.config.ignore_comments => {

0 commit comments

Comments
 (0)