Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1140,7 +1140,7 @@ impl IDocumentTrait for Document {
///
/// # Examples
///
/// ```
/// ```ignore
/// use visdom::Vis;
/// use visdom::types::BoxDynError;
/// fn main()-> Result<(), BoxDynError>{
Expand Down
2 changes: 1 addition & 1 deletion src/mesdoc/interface/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl IntoIterator for IFormValue {
fn into_iter(self) -> Self::IntoIter {
match self {
IFormValue::Multiple(v) => v.into_iter(),
IFormValue::Single(_) => vec![].into_iter(),
IFormValue::Single(v) => vec![v].into_iter(),
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/mesdoc/interface/elements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ enum ElementRelation {
Ancestor,
Equal,
Descendant,
Feauture,
Feature,
}
// check if ancestor and descendants
fn relation_of(a: &VecDeque<usize>, b: &VecDeque<usize>) -> ElementRelation {
Expand All @@ -81,7 +81,7 @@ fn relation_of(a: &VecDeque<usize>, b: &VecDeque<usize>) -> ElementRelation {
let a_left = a_total - equal_num;
let b_left = b_total - equal_num;
match (a_left == 0, b_left == 0) {
(false, false) => ElementRelation::Feauture,
(false, false) => ElementRelation::Feature,
(false, true) => ElementRelation::Descendant,
(true, true) => ElementRelation::Equal,
(true, false) => ElementRelation::Ancestor,
Expand Down Expand Up @@ -458,7 +458,7 @@ impl<'a> Elements<'a> {
// just check the last ancestor
let (top_ele_indexs, _) = &ancestors[cur_len - 1];
match relation_of(&ele_indexs, top_ele_indexs) {
ElementRelation::Feauture => {
ElementRelation::Feature => {
ancestors.push((ele_indexs, ele));
}
ElementRelation::Descendant => {}
Expand Down Expand Up @@ -3866,9 +3866,9 @@ mod tests {
assert!(matches!(relation_of(&a, &b), ElementRelation::Ancestor));
assert!(matches!(relation_of(&b, &a), ElementRelation::Descendant));
let c: VecDeque<usize> = vec![1, 2, 3].into();
assert!(matches!(relation_of(&b, &c), ElementRelation::Feauture));
assert!(matches!(relation_of(&c, &b), ElementRelation::Feauture));
assert!(matches!(relation_of(&c, &a), ElementRelation::Feauture));
assert!(matches!(relation_of(&b, &c), ElementRelation::Feature));
assert!(matches!(relation_of(&c, &b), ElementRelation::Feature));
assert!(matches!(relation_of(&c, &a), ElementRelation::Feature));
let d: VecDeque<usize> = vec![0, 1].into();
assert!(matches!(relation_of(&b, &d), ElementRelation::Equal));
}
Expand Down
8 changes: 3 additions & 5 deletions src/mesdoc/selector/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,22 +224,20 @@ impl Selector {
let mut max_index: usize = 0;
let mut max_priority: u32 = 0;
for (index, r) in group.iter_mut().enumerate() {
let mut total_priority = 0;
if r.len() > 1 {
let chain_comb = r[0].1;
r.sort_by(|a, b| b.0.priority.partial_cmp(&a.0.priority).unwrap());
#[allow(clippy::unnecessary_sort_by)]
r.sort_by(|a, b| b.0.priority.cmp(&a.0.priority));
let now_first = &mut r[0];
if now_first.1 != chain_comb {
now_first.1 = chain_comb;
total_priority += now_first.0.priority;
for n in &mut r[1..] {
n.1 = Combinator::Chain;
total_priority += n.0.priority;
}
}
}
if use_lookup {
total_priority = r.iter().map(|p| p.0.priority).sum();
let total_priority: u32 = r.iter().map(|p| p.0.priority).sum();
if total_priority > max_priority {
max_priority = total_priority;
max_index = index;
Expand Down
16 changes: 14 additions & 2 deletions src/mesdoc/selector/pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ pub trait Pattern: Send + Sync + Debug {

impl Pattern for char {
fn matched(&self, chars: &[char]) -> Option<Matched> {
if chars.is_empty() {
return None;
}
let ch = chars[0];
if *self == ch {
return Some(Matched {
Expand Down Expand Up @@ -92,6 +95,9 @@ pub struct Identity;

impl Pattern for Identity {
fn matched(&self, chars: &[char]) -> Option<Matched> {
if chars.is_empty() {
return None;
}
let mut result: Vec<char> = Vec::with_capacity(5);
let first = chars[0];
let name: &str = "identity";
Expand Down Expand Up @@ -269,10 +275,16 @@ impl Nth {
) -> Vec<usize> {
// has n
if let Some(n) = n {
let n = n.parse::<isize>().unwrap();
let n = n
.parse::<isize>()
.expect("nth 'n' value must be a valid integer");
let index = index
.as_ref()
.map(|index| index.parse::<isize>().unwrap())
.map(|index| {
index
.parse::<isize>()
.expect("nth 'index' value must be a valid integer")
})
.unwrap_or(0);
// n == 0
if n == 0 {
Expand Down
12 changes: 5 additions & 7 deletions src/mesdoc/selector/rule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ impl Matcher {
if let Some(handle) = &self.all_handle {
return handle(eles, use_cache);
}
let handle = self.one_handle.as_ref().unwrap();
let handle = self
.one_handle
.as_ref()
.expect("Matcher must have either all_handle or one_handle");
let mut result = Elements::with_capacity(5);
for ele in eles.get_ref() {
if handle(&**ele, use_cache) {
Expand Down Expand Up @@ -139,12 +142,7 @@ impl Rule {
let mut index: usize = 0;
for ch in content.chars() {
index += 1;
let is_prev_matched_finish = if is_matched_finish {
is_matched_finish = false;
true
} else {
false
};
let is_prev_matched_finish = std::mem::take(&mut is_matched_finish);
if store.is_wait_end {
if ch.is_ascii_whitespace() {
continue;
Expand Down
22 changes: 3 additions & 19 deletions src/mesdoc/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,12 @@ pub fn divide_isize(a: isize, b: isize, round: RoundType) -> isize {
}

pub fn retain_by_index<T>(v: &mut Vec<T>, indexs: &[usize]) {
for (i, index) in indexs.iter().enumerate() {
v.remove(index - i);
}
/*
let mut loop_index: usize = 0;
v.retain(|_| {
let removed = indexs.contains(&loop_index);
loop_index += 1;
!removed
});
*/
}

// get a class list from class attribute
Expand Down Expand Up @@ -174,8 +169,7 @@ pub fn is_equal_chars_ignore_case(target: &[char], cmp: &[char]) -> bool {
if target.len() != cmp.len() {
return false;
}
for (index, ch) in target.iter().enumerate() {
let cmp_ch = &cmp[index];
for (ch, cmp_ch) in target.iter().zip(cmp.iter()) {
if cmp_ch == ch {
continue;
}
Expand All @@ -191,7 +185,6 @@ pub fn is_equal_chars_ignore_case(target: &[char], cmp: &[char]) -> bool {
}
}
_ => {
// not equal
return false;
}
}
Expand All @@ -200,17 +193,7 @@ pub fn is_equal_chars_ignore_case(target: &[char], cmp: &[char]) -> bool {
}

pub fn is_equal_chars(target: &[char], cmp: &[char]) -> bool {
let t_len = target.len();
let s_len = cmp.len();
if t_len == s_len {
for (index, ch) in target.iter().enumerate() {
if ch != &cmp[index] {
return false;
}
}
return true;
}
false
target == cmp
}

fn contains_chars_nocheck(target: &[char], search: &[char], t_len: usize, s_len: usize) -> bool {
Expand All @@ -224,6 +207,7 @@ fn contains_chars_nocheck(target: &[char], search: &[char], t_len: usize, s_len:
continue;
}
move_one = true;
break;
}
if !move_one {
return true;
Expand Down
Loading