Skip to content

Commit 77c9640

Browse files
committed
a-Z for DimElement
1 parent b61fda7 commit 77c9640

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

svd-rs/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## Unreleased
99

10+
- Add support of `a-Z` for `dimIndex`
1011
- Add `name`, `description`, `address_offset` for `RegisterCluster`
1112

1213
## [v0.14.1] - 2022-10-23

svd-rs/src/dimelement.rs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -144,15 +144,26 @@ impl DimElement {
144144

145145
/// Get array of indexes from string
146146
pub fn parse_indexes(text: &str) -> Option<Vec<String>> {
147-
if text.contains('-') {
148-
let mut parts = text.splitn(2, '-');
149-
let start = parts.next()?.parse::<u32>().ok()?;
150-
let end = parts.next()?.parse::<u32>().ok()?;
151-
152-
Some((start..=end).map(|i| i.to_string()).collect())
147+
(if text.contains('-') {
148+
let (start, end) = text.split_once('-')?;
149+
if let (Ok(start), Ok(end)) = (start.parse::<u32>(), end.parse::<u32>()) {
150+
Some((start..=end).map(|i| i.to_string()).collect::<Vec<_>>())
151+
} else {
152+
let mut start = start.bytes();
153+
let mut end = end.bytes();
154+
match (start.next(), start.next(), end.next(), end.next()) {
155+
(Some(start), None, Some(end), None)
156+
if start.is_ascii_alphabetic() && end.is_ascii_alphabetic() =>
157+
{
158+
Some((start..=end).map(|c| char::from(c).to_string()).collect())
159+
}
160+
_ => None,
161+
}
162+
}
153163
} else {
154164
Some(text.split(',').map(|s| s.to_string()).collect())
155-
}
165+
})
166+
.filter(|v| !v.is_empty())
156167
}
157168
/// Try to represent [`DimElement`] as range of integer indexes
158169
pub fn indexes_as_range(&self) -> Option<RangeInclusive<u32>> {

0 commit comments

Comments
 (0)