Skip to content

Commit

Permalink
Merge pull request #241 from rust-embedded/range
Browse files Browse the repository at this point in the history
fix indexes_as_range
  • Loading branch information
Emilgardis authored Nov 15, 2023
2 parents 4680d8d + ebf7204 commit a54d1e5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions svd-rs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## Unreleased

- Fix `indexes_as_range`

## [v0.14.3] - 2023-04-04

- Bump MSRV to 1.58.0
Expand Down
8 changes: 7 additions & 1 deletion svd-rs/src/dimelement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,13 @@ impl DimElement {
pub fn indexes_as_range(&self) -> Option<RangeInclusive<u32>> {
let mut integers = Vec::with_capacity(self.dim as usize);
for idx in self.indexes() {
integers.push(idx.parse::<u32>().ok()?);
// XXX: indexes that begin with leading zero are not compatible with range (`0-x`) syntax in serialization
// see https://github.com/rust-embedded/svdtools/pull/178#issuecomment-1801433808
let val = idx.parse::<u32>().ok()?;
if val.to_string() != idx {
return None;
}
integers.push(val);
}
let min = *integers.iter().min()?;
let max = *integers.iter().max()?;
Expand Down

0 comments on commit a54d1e5

Please sign in to comment.