Skip to content

Commit

Permalink
loop find
Browse files Browse the repository at this point in the history
  • Loading branch information
burrbull committed Nov 24, 2023
1 parent 90f53bb commit fa4cd5a
Showing 1 changed file with 41 additions and 14 deletions.
55 changes: 41 additions & 14 deletions src/patch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -641,20 +641,47 @@ fn check_offsets(offsets: &[u32], dim_increment: u32) -> bool {
/// Tries to get common description (or displayNames) for register/field array with "%s" in index position.
/// Returns `None` if incoming descriptions have more then 1 difference
fn common_description(descs: &[Option<&str>], dim_index: &[String]) -> Option<Option<String>> {
let mut dsc = None;
let mut first = true;
for (d, idx) in descs.iter().zip(dim_index) {
if first {
dsc = d.map(|desc| desc.replacen(idx, "%s", 1));
} else if d
!= &dsc
.as_ref()
.map(|desc| desc.replacen("%s", idx, 1))
.as_deref()
{
return None;
if let Some(desc0) = descs[0] {
let idx0 = &dim_index[0];
if desc0.contains(idx0) {
for (i1, _) in desc0.match_indices(idx0) {
let (s1, sx) = desc0.split_at(i1);
let (_, s2) = sx.split_at(idx0.len());
let dsc = Some(format!("{s1}%s{s2}"));
let mut same = true;
for (d, idx) in descs.iter().zip(dim_index).skip(1) {
if d != &dsc
.as_ref()
.map(|desc| desc.replacen("%s", idx, 1))
.as_deref()
{
same = false;
break;
}
}
if same {
return Some(dsc);
}
}
None
} else {
let mut same = true;
for (d, idx) in descs.iter().zip(dim_index).skip(1) {
match d {
Some(d) if d == &desc0 && !d.contains(idx) => {}
_ => {
same = false;
break;
}
}
}
if same {
Some(Some(desc0.into()))
} else {
None
}
}
first = false;
} else {
None
}
Some(dsc.map(Into::into))
}

0 comments on commit fa4cd5a

Please sign in to comment.