-
Notifications
You must be signed in to change notification settings - Fork 238
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds NsReader::prefixes to iterate on all the prefixes currently declared #705
Conversation
Sorry for the out-of-the-blue PR. Don't feel bad for rejecting/requesting big changes. Thank you so much for quick-xml |
Codecov ReportAll modified and coverable lines are covered by tests ✅
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## master #705 +/- ##
==========================================
+ Coverage 65.39% 65.46% +0.07%
==========================================
Files 38 38
Lines 18128 18165 +37
==========================================
+ Hits 11854 11892 +38
+ Misses 6274 6273 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is nice addition!
Could you add changelog entry and a doctest to better explain the results of the new method. There is also a couple of questions that I left in the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your so quick code review. I have made the changes you suggested
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! A minor fix in changelog is required and it seems to me a small optimization is possible
Changelog.md
Outdated
@@ -29,6 +29,7 @@ to get an offset of the error position. For `SyntaxError`s the range | |||
- [#362]: Added `escape::minimal_escape()` which escapes only `&` and `<`. | |||
- [#362]: Added `BytesCData::minimal_escape()` which escapes only `&` and `<`. | |||
- [#362]: Added `Serializer::set_quote_level()` which allow to set desired level of escaping. | |||
- `NsReader::prefixes` to list all the prefixes currently declared. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- `NsReader::prefixes` to list all the prefixes currently declared. | |
- [#705]: Added `NsReader::prefixes()` to list all the prefixes currently declared. |
and add link to this PR at line 70
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
src/name.rs
Outdated
if self.resolver.bindings[self.bindings_cursor..] | ||
.iter() | ||
.any(|ne| { | ||
namespace_entry.prefix(&self.resolver.buffer) | ||
== ne.prefix(&self.resolver.buffer) | ||
}) | ||
{ | ||
continue; // Overriden | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems we can return None
here because on all next iterations we also enter in this if
, don't we?
Also, namespace_entry.prefix(&self.resolver.buffer)
could be calculated outside of closure and I have a feeling that the whole this loop can be embedded.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, namespace_entry.prefix(&self.resolver.buffer) could be calculated outside of closure and I have a feeling that the whole this loop can be embedded.
Indeed. Done. Thank you!
It seems we can return None here because on all next iterations we also enter in this if, don't we?
I don't think so because we check only if a namespace of the same name is declared, not if an other namespace in general is declared.
Let's say we have
<foo:outer xmlns:foo="a" xmlns:bar="b">
<foo:inner xmlns:foo="c"></foo:inner>
</foo:outer>
The bindings
list when parsing foo:inner
is going to be something like [("foo", "a"), ("bar", "b"), ("foo", "c")]
so, when we iterate on it we don't want to stop iterating on the first ("foo", "a")
because it has been overriden by ("foo", "c")
.
src/name.rs
Outdated
} | ||
|
||
fn size_hint(&self) -> (usize, Option<usize>) { | ||
(0, Some(self.resolver.bindings.len() - 2)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(0, Some(self.resolver.bindings.len() - 2)) | |
// -2 for xml and xmlns prefixes that are always stored in bindings | |
(0, Some(self.resolver.bindings.len() - 2)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Thank you! Done. |
…ared This is useful for some use cases like RDF/XML where prefixes might be interesting to extract
I've made returned iterator Thanks for your work, @Tpt! |
This is useful for some use cases like RDF/XML where prefixes might be interesting to extract