Skip to content

Commit e7e5222

Browse files
committed
Emit actual encoding event
1 parent 62a6f6d commit e7e5222

File tree

8 files changed

+14
-25
lines changed

8 files changed

+14
-25
lines changed

design.md

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,13 @@
22

33
Basic features:
44
* [x] Parsing XML 1.0 documents and returning a stream of events
5-
- [ ] Support reading embedded DTD schemas
6-
- [ ] Support for embedded entities
5+
- [x] Support for embedded entities
76
* [x] Support for namespaces and emitting namespace information in events
8-
* [ ] \[maybe\] push-based wrapper
97
* Missing XML features
10-
- [ ] Support for different encodings
8+
- [x] Support for different encodings
119
- [ ] Attribute values normalization
1210
- [ ] EOL characters normalization
1311

14-
Advanced features:
15-
* [ ] DTD schema validation
16-
* [ ] XSD schema validation
17-
1812
# Writer
1913

2014
Basic features:
@@ -30,8 +24,3 @@ Basic features:
3024
- [ ] Check for namespaces more correctly, i.e. check both for prefix and namespace URI
3125
- [ ] Support checking namespace prefix presence in the current namespace for events with prefix but without namespace
3226
- [ ] Support checking namespace prefix for events with both prefix and namespace URI
33-
34-
# Other
35-
36-
DOM-based API:
37-
* [ ] Basic support for DOM-based API

src/reader/parser.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ mod inside_reference;
5757
mod outside_tag;
5858

5959
static DEFAULT_VERSION: XmlVersion = XmlVersion::Version10;
60-
static DEFAULT_ENCODING: &str = "UTF-8";
6160
static DEFAULT_STANDALONE: Option<bool> = None;
6261

6362
type ElementStack = Vec<OwnedName>;

src/reader/parser/inside_declaration.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::reader::lexer::Token;
55
use crate::util::Encoding;
66

77
use super::{
8-
DeclarationSubstate, PullParser, QualifiedNameTarget, Result, State, DEFAULT_ENCODING,
8+
DeclarationSubstate, PullParser, QualifiedNameTarget, Result, State,
99
DEFAULT_VERSION,
1010
};
1111

@@ -35,9 +35,10 @@ impl PullParser {
3535
}
3636
}
3737

38+
let current_encoding = self.lexer.encoding();
3839
self.into_state_emit(State::OutsideTag, Ok(XmlEvent::StartDocument {
3940
version: version.unwrap_or(DEFAULT_VERSION),
40-
encoding: encoding.unwrap_or(DEFAULT_ENCODING.into()),
41+
encoding: encoding.unwrap_or_else(move || current_encoding.to_string()),
4142
standalone
4243
}))
4344
}

src/reader/parser/outside_tag.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::reader::lexer::Token;
55

66
use super::{
77
ClosingTagSubstate, OpeningTagSubstate, ProcessingInstructionSubstate, PullParser, Result,
8-
State, DEFAULT_ENCODING, DEFAULT_STANDALONE, DEFAULT_VERSION, DoctypeSubstate,
8+
State, DEFAULT_STANDALONE, DEFAULT_VERSION, DoctypeSubstate,
99
};
1010

1111
impl PullParser {
@@ -94,7 +94,7 @@ impl PullParser {
9494
self.parsed_declaration = true;
9595
let sd_event = XmlEvent::StartDocument {
9696
version: DEFAULT_VERSION,
97-
encoding: DEFAULT_ENCODING.into(),
97+
encoding: self.lexer.encoding().to_string(),
9898
standalone: DEFAULT_STANDALONE
9999
};
100100
// next_event is always none here because we're outside of

src/util.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,13 @@ impl fmt::Display for Encoding {
8686
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
8787
f.write_str(match self {
8888
Encoding::Utf8 => "UTF-8",
89-
Encoding::Default => "UTF-8 (default)",
89+
Encoding::Default => "UTF-8",
9090
Encoding::Latin1 => "ISO-8859-1",
9191
Encoding::Ascii => "US-ASCII",
92-
Encoding::Utf16Be => "UTF-16 (BE)",
93-
Encoding::Utf16Le => "UTF-16 (LE)",
92+
Encoding::Utf16Be => "UTF-16",
93+
Encoding::Utf16Le => "UTF-16",
9494
Encoding::Utf16 => "UTF-16",
95-
Encoding::Unknown => "Unknown",
95+
Encoding::Unknown => "(unknown)",
9696
})
9797
}
9898
}

tests/documents/sample_1.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
1+
<?xml version="1.0" encoding="iso-8859-1" standalone="yes"?>
22
<project name="project-name">
33
<libraries>
44
<library groupId="org.example" artifactId="&lt;name&gt;" version="0.1"/>

tests/documents/sample_1_full.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
StartDocument(1.0, utf-8)
1+
StartDocument(1.0, iso-8859-1)
22
StartElement(project [name="project-name"])
33
Whitespace("\n ")
44
StartElement(libraries)

tests/documents/sample_1_short.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
StartDocument(1.0, utf-8)
1+
StartDocument(1.0, iso-8859-1)
22
StartElement(project [name="project-name"])
33
StartElement(libraries)
44
StartElement(library [groupId="org.example", artifactId="<name>", version="0.1"])

0 commit comments

Comments
 (0)