Skip to content

Commit 5226a15

Browse files
bors[bot]burrbull
andauthored
Merge #222
222: A-Z/a-z for DimElement r=Emilgardis a=burrbull Should fix #212 cc `@n8tlarsen` Test, please Co-authored-by: Andrey Zgarbul <[email protected]>
2 parents 835d32c + 032d05b commit 5226a15

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-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: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -144,15 +144,27 @@ 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_lowercase() && end.is_ascii_lowercase())
157+
|| (start.is_ascii_uppercase() && end.is_ascii_uppercase()) =>
158+
{
159+
Some((start..=end).map(|c| char::from(c).to_string()).collect())
160+
}
161+
_ => None,
162+
}
163+
}
153164
} else {
154165
Some(text.split(',').map(|s| s.to_string()).collect())
155-
}
166+
})
167+
.filter(|v| !v.is_empty())
156168
}
157169
/// Try to represent [`DimElement`] as range of integer indexes
158170
pub fn indexes_as_range(&self) -> Option<RangeInclusive<u32>> {

0 commit comments

Comments
 (0)