Skip to content

Commit 123b87c

Browse files
committed
custom names for arrays
1 parent 4ea70fb commit 123b87c

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

svd-rs/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
99

1010
- Bump MSRV to 1.58.0
1111

12+
- `array::names` returns custom names if specified
13+
1214
## [v0.14.2] - 2023-04-04
1315

1416
- Add support of `a-Z` for `dimIndex`

svd-rs/src/array.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,18 @@ where
5353
/// Return list of names of instances in array
5454
pub fn names<'a, T: Name>(info: &'a T, dim: &'a DimElement) -> impl Iterator<Item = String> + 'a {
5555
let name = info.name();
56-
dim.indexes()
57-
.map(move |i| name.replace("[%s]", &i).replace("%s", &i))
56+
dim.indexes().map(move |i| {
57+
dim.dim_array_index
58+
.as_ref()
59+
.map(|dai| {
60+
dai.values
61+
.iter()
62+
.find(|e| e.value.map(|v| v.to_string().as_str() == i.deref()) == Some(true))
63+
})
64+
.flatten()
65+
.map(|n| n.name.clone())
66+
.unwrap_or_else(|| name.replace("[%s]", &i).replace("%s", &i))
67+
})
5868
}
5969

6070
#[cfg(feature = "serde")]

0 commit comments

Comments
 (0)