mirror of
https://github.com/ClementTsang/bottom.git
synced 2025-07-24 06:05:10 +02:00
refactor: fix clippy error
This commit is contained in:
parent
b33ea11af2
commit
c7edad91ed
396
src/app/query.rs
396
src/app/query.rs
@ -163,98 +163,118 @@ impl ProcessQuery for ProcWidgetState {
|
|||||||
compare_prefix: None,
|
compare_prefix: None,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else if queue_top == "(" {
|
||||||
if queue_top == "(" {
|
if query.is_empty() {
|
||||||
if query.is_empty() {
|
return Err(QueryError("Missing closing parentheses".into()));
|
||||||
return Err(QueryError("Missing closing parentheses".into()));
|
}
|
||||||
|
|
||||||
|
let mut list_of_ors = VecDeque::new();
|
||||||
|
|
||||||
|
while let Some(in_paren_query_top) = query.front() {
|
||||||
|
if in_paren_query_top != ")" {
|
||||||
|
list_of_ors.push_back(process_or(query)?);
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let mut list_of_ors = VecDeque::new();
|
// Ensure not empty
|
||||||
|
if list_of_ors.is_empty() {
|
||||||
|
return Err(QueryError("No values within parentheses group".into()));
|
||||||
|
}
|
||||||
|
|
||||||
while let Some(in_paren_query_top) = query.front() {
|
// Now convert this back to a OR...
|
||||||
if in_paren_query_top != ")" {
|
let mut returned_or = Or {
|
||||||
list_of_ors.push_back(process_or(query)?);
|
lhs: And {
|
||||||
} else {
|
lhs: Prefix {
|
||||||
break;
|
or: Some(Box::new(list_of_ors.pop_front().unwrap())),
|
||||||
}
|
compare_prefix: None,
|
||||||
}
|
regex_prefix: None,
|
||||||
|
},
|
||||||
// Ensure not empty
|
rhs: None,
|
||||||
if list_of_ors.is_empty() {
|
},
|
||||||
return Err(QueryError("No values within parentheses group".into()));
|
rhs: None,
|
||||||
}
|
};
|
||||||
|
list_of_ors.into_iter().for_each(|rhs| {
|
||||||
// Now convert this back to a OR...
|
returned_or = Or {
|
||||||
let mut returned_or = Or {
|
|
||||||
lhs: And {
|
lhs: And {
|
||||||
lhs: Prefix {
|
lhs: Prefix {
|
||||||
or: Some(Box::new(list_of_ors.pop_front().unwrap())),
|
or: Some(Box::new(returned_or.clone())),
|
||||||
compare_prefix: None,
|
compare_prefix: None,
|
||||||
regex_prefix: None,
|
regex_prefix: None,
|
||||||
},
|
},
|
||||||
rhs: None,
|
rhs: Some(Box::new(Prefix {
|
||||||
|
or: Some(Box::new(rhs)),
|
||||||
|
compare_prefix: None,
|
||||||
|
regex_prefix: None,
|
||||||
|
})),
|
||||||
},
|
},
|
||||||
rhs: None,
|
rhs: None,
|
||||||
};
|
};
|
||||||
list_of_ors.into_iter().for_each(|rhs| {
|
});
|
||||||
returned_or = Or {
|
|
||||||
lhs: And {
|
|
||||||
lhs: Prefix {
|
|
||||||
or: Some(Box::new(returned_or.clone())),
|
|
||||||
compare_prefix: None,
|
|
||||||
regex_prefix: None,
|
|
||||||
},
|
|
||||||
rhs: Some(Box::new(Prefix {
|
|
||||||
or: Some(Box::new(rhs)),
|
|
||||||
compare_prefix: None,
|
|
||||||
regex_prefix: None,
|
|
||||||
})),
|
|
||||||
},
|
|
||||||
rhs: None,
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
if let Some(close_paren) = query.pop_front() {
|
if let Some(close_paren) = query.pop_front() {
|
||||||
if close_paren == ")" {
|
if close_paren == ")" {
|
||||||
return Ok(Prefix {
|
return Ok(Prefix {
|
||||||
or: Some(Box::new(returned_or)),
|
or: Some(Box::new(returned_or)),
|
||||||
regex_prefix: None,
|
regex_prefix: None,
|
||||||
compare_prefix: None,
|
compare_prefix: None,
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
return Err(QueryError("Missing closing parentheses".into()));
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
return Err(QueryError("Missing closing parentheses".into()));
|
return Err(QueryError("Missing closing parentheses".into()));
|
||||||
}
|
}
|
||||||
} else if queue_top == ")" {
|
} else {
|
||||||
return Err(QueryError("Missing opening parentheses".into()));
|
return Err(QueryError("Missing closing parentheses".into()));
|
||||||
} else if queue_top == "\"" {
|
}
|
||||||
// Similar to parentheses, trap and check for missing closing quotes. Note, however, that we
|
} else if queue_top == ")" {
|
||||||
// will DIRECTLY call another process_prefix call...
|
return Err(QueryError("Missing opening parentheses".into()));
|
||||||
|
} else if queue_top == "\"" {
|
||||||
|
// Similar to parentheses, trap and check for missing closing quotes. Note, however, that we
|
||||||
|
// will DIRECTLY call another process_prefix call...
|
||||||
|
|
||||||
let prefix = process_prefix(query, true)?;
|
let prefix = process_prefix(query, true)?;
|
||||||
if let Some(close_paren) = query.pop_front() {
|
if let Some(close_paren) = query.pop_front() {
|
||||||
if close_paren == "\"" {
|
if close_paren == "\"" {
|
||||||
return Ok(prefix);
|
return Ok(prefix);
|
||||||
} else {
|
|
||||||
return Err(QueryError("Missing closing quotation".into()));
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
return Err(QueryError("Missing closing quotation".into()));
|
return Err(QueryError("Missing closing quotation".into()));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Get prefix type...
|
return Err(QueryError("Missing closing quotation".into()));
|
||||||
let prefix_type = queue_top.parse::<PrefixType>()?;
|
}
|
||||||
let content = if let PrefixType::Name = prefix_type {
|
} else {
|
||||||
Some(queue_top)
|
// Get prefix type...
|
||||||
} else {
|
let prefix_type = queue_top.parse::<PrefixType>()?;
|
||||||
query.pop_front()
|
let content = if let PrefixType::Name = prefix_type {
|
||||||
};
|
Some(queue_top)
|
||||||
|
} else {
|
||||||
|
query.pop_front()
|
||||||
|
};
|
||||||
|
|
||||||
if let Some(content) = content {
|
if let Some(content) = content {
|
||||||
match &prefix_type {
|
match &prefix_type {
|
||||||
PrefixType::Name => {
|
PrefixType::Name => {
|
||||||
|
return Ok(Prefix {
|
||||||
|
or: None,
|
||||||
|
regex_prefix: Some((prefix_type, StringQuery::Value(content))),
|
||||||
|
compare_prefix: None,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
PrefixType::Pid => {
|
||||||
|
// We have to check if someone put an "="...
|
||||||
|
if content == "=" {
|
||||||
|
// Check next string if possible
|
||||||
|
if let Some(queue_next) = query.pop_front() {
|
||||||
|
return Ok(Prefix {
|
||||||
|
or: None,
|
||||||
|
regex_prefix: Some((
|
||||||
|
prefix_type,
|
||||||
|
StringQuery::Value(queue_next),
|
||||||
|
)),
|
||||||
|
compare_prefix: None,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
return Ok(Prefix {
|
return Ok(Prefix {
|
||||||
or: None,
|
or: None,
|
||||||
regex_prefix: Some((
|
regex_prefix: Some((
|
||||||
@ -262,149 +282,123 @@ impl ProcessQuery for ProcWidgetState {
|
|||||||
StringQuery::Value(content),
|
StringQuery::Value(content),
|
||||||
)),
|
)),
|
||||||
compare_prefix: None,
|
compare_prefix: None,
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
PrefixType::Pid => {
|
}
|
||||||
// We have to check if someone put an "="...
|
_ => {
|
||||||
if content == "=" {
|
// Now we gotta parse the content... yay.
|
||||||
// Check next string if possible
|
|
||||||
if let Some(queue_next) = query.pop_front() {
|
let mut condition: Option<QueryComparison> = None;
|
||||||
return Ok(Prefix {
|
let mut value: Option<f64> = None;
|
||||||
or: None,
|
|
||||||
regex_prefix: Some((
|
if content == "=" {
|
||||||
prefix_type,
|
condition = Some(QueryComparison::Equal);
|
||||||
StringQuery::Value(queue_next),
|
if let Some(queue_next) = query.pop_front() {
|
||||||
)),
|
value = queue_next.parse::<f64>().ok();
|
||||||
compare_prefix: None,
|
} else {
|
||||||
|
return Err(QueryError("Missing value".into()));
|
||||||
|
}
|
||||||
|
} else if content == ">" || content == "<" {
|
||||||
|
// We also have to check if the next string is an "="...
|
||||||
|
if let Some(queue_next) = query.pop_front() {
|
||||||
|
if queue_next == "=" {
|
||||||
|
condition = Some(if content == ">" {
|
||||||
|
QueryComparison::GreaterOrEqual
|
||||||
|
} else {
|
||||||
|
QueryComparison::LessOrEqual
|
||||||
});
|
});
|
||||||
|
if let Some(queue_next_next) = query.pop_front() {
|
||||||
|
value = queue_next_next.parse::<f64>().ok();
|
||||||
|
} else {
|
||||||
|
return Err(QueryError("Missing value".into()));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
condition = Some(if content == ">" {
|
||||||
|
QueryComparison::Greater
|
||||||
|
} else {
|
||||||
|
QueryComparison::Less
|
||||||
|
});
|
||||||
|
value = queue_next.parse::<f64>().ok();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
return Err(QueryError("Missing value".into()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(condition) = condition {
|
||||||
|
if let Some(read_value) = value {
|
||||||
|
// Now we want to check one last thing - is there a unit?
|
||||||
|
// If no unit, assume base.
|
||||||
|
// Furthermore, base must be PEEKED at initially, and will
|
||||||
|
// require (likely) prefix_type specific checks
|
||||||
|
// Lastly, if it *is* a unit, remember to POP!
|
||||||
|
|
||||||
|
let mut value = read_value;
|
||||||
|
|
||||||
|
match prefix_type {
|
||||||
|
PrefixType::Rps
|
||||||
|
| PrefixType::Wps
|
||||||
|
| PrefixType::TRead
|
||||||
|
| PrefixType::TWrite => {
|
||||||
|
if let Some(potential_unit) = query.front() {
|
||||||
|
match potential_unit.to_lowercase().as_str() {
|
||||||
|
"tb" => {
|
||||||
|
value *= 1_000_000_000_000.0;
|
||||||
|
query.pop_front();
|
||||||
|
}
|
||||||
|
"tib" => {
|
||||||
|
value *= 1_099_511_627_776.0;
|
||||||
|
query.pop_front();
|
||||||
|
}
|
||||||
|
"gb" => {
|
||||||
|
value *= 1_000_000_000.0;
|
||||||
|
query.pop_front();
|
||||||
|
}
|
||||||
|
"gib" => {
|
||||||
|
value *= 1_073_741_824.0;
|
||||||
|
query.pop_front();
|
||||||
|
}
|
||||||
|
"mb" => {
|
||||||
|
value *= 1_000_000.0;
|
||||||
|
query.pop_front();
|
||||||
|
}
|
||||||
|
"mib" => {
|
||||||
|
value *= 1_048_576.0;
|
||||||
|
query.pop_front();
|
||||||
|
}
|
||||||
|
"kb" => {
|
||||||
|
value *= 1000.0;
|
||||||
|
query.pop_front();
|
||||||
|
}
|
||||||
|
"kib" => {
|
||||||
|
value *= 1024.0;
|
||||||
|
query.pop_front();
|
||||||
|
}
|
||||||
|
"b" => {
|
||||||
|
// Just gotta pop.
|
||||||
|
query.pop_front();
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
|
||||||
return Ok(Prefix {
|
return Ok(Prefix {
|
||||||
or: None,
|
or: None,
|
||||||
regex_prefix: Some((
|
regex_prefix: None,
|
||||||
|
compare_prefix: Some((
|
||||||
prefix_type,
|
prefix_type,
|
||||||
StringQuery::Value(content),
|
NumericalQuery { condition, value },
|
||||||
)),
|
)),
|
||||||
compare_prefix: None,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {
|
|
||||||
// Now we gotta parse the content... yay.
|
|
||||||
|
|
||||||
let mut condition: Option<QueryComparison> = None;
|
|
||||||
let mut value: Option<f64> = None;
|
|
||||||
|
|
||||||
if content == "=" {
|
|
||||||
condition = Some(QueryComparison::Equal);
|
|
||||||
if let Some(queue_next) = query.pop_front() {
|
|
||||||
value = queue_next.parse::<f64>().ok();
|
|
||||||
} else {
|
|
||||||
return Err(QueryError("Missing value".into()));
|
|
||||||
}
|
|
||||||
} else if content == ">" || content == "<" {
|
|
||||||
// We also have to check if the next string is an "="...
|
|
||||||
if let Some(queue_next) = query.pop_front() {
|
|
||||||
if queue_next == "=" {
|
|
||||||
condition = Some(if content == ">" {
|
|
||||||
QueryComparison::GreaterOrEqual
|
|
||||||
} else {
|
|
||||||
QueryComparison::LessOrEqual
|
|
||||||
});
|
|
||||||
if let Some(queue_next_next) = query.pop_front() {
|
|
||||||
value = queue_next_next.parse::<f64>().ok();
|
|
||||||
} else {
|
|
||||||
return Err(QueryError("Missing value".into()));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
condition = Some(if content == ">" {
|
|
||||||
QueryComparison::Greater
|
|
||||||
} else {
|
|
||||||
QueryComparison::Less
|
|
||||||
});
|
|
||||||
value = queue_next.parse::<f64>().ok();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return Err(QueryError("Missing value".into()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(condition) = condition {
|
|
||||||
if let Some(read_value) = value {
|
|
||||||
// Now we want to check one last thing - is there a unit?
|
|
||||||
// If no unit, assume base.
|
|
||||||
// Furthermore, base must be PEEKED at initially, and will
|
|
||||||
// require (likely) prefix_type specific checks
|
|
||||||
// Lastly, if it *is* a unit, remember to POP!
|
|
||||||
|
|
||||||
let mut value = read_value;
|
|
||||||
|
|
||||||
match prefix_type {
|
|
||||||
PrefixType::Rps
|
|
||||||
| PrefixType::Wps
|
|
||||||
| PrefixType::TRead
|
|
||||||
| PrefixType::TWrite => {
|
|
||||||
if let Some(potential_unit) = query.front() {
|
|
||||||
match potential_unit.to_lowercase().as_str()
|
|
||||||
{
|
|
||||||
"tb" => {
|
|
||||||
value *= 1_000_000_000_000.0;
|
|
||||||
query.pop_front();
|
|
||||||
}
|
|
||||||
"tib" => {
|
|
||||||
value *= 1_099_511_627_776.0;
|
|
||||||
query.pop_front();
|
|
||||||
}
|
|
||||||
"gb" => {
|
|
||||||
value *= 1_000_000_000.0;
|
|
||||||
query.pop_front();
|
|
||||||
}
|
|
||||||
"gib" => {
|
|
||||||
value *= 1_073_741_824.0;
|
|
||||||
query.pop_front();
|
|
||||||
}
|
|
||||||
"mb" => {
|
|
||||||
value *= 1_000_000.0;
|
|
||||||
query.pop_front();
|
|
||||||
}
|
|
||||||
"mib" => {
|
|
||||||
value *= 1_048_576.0;
|
|
||||||
query.pop_front();
|
|
||||||
}
|
|
||||||
"kb" => {
|
|
||||||
value *= 1000.0;
|
|
||||||
query.pop_front();
|
|
||||||
}
|
|
||||||
"kib" => {
|
|
||||||
value *= 1024.0;
|
|
||||||
query.pop_front();
|
|
||||||
}
|
|
||||||
"b" => {
|
|
||||||
// Just gotta pop.
|
|
||||||
query.pop_front();
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
|
|
||||||
return Ok(Prefix {
|
|
||||||
or: None,
|
|
||||||
regex_prefix: None,
|
|
||||||
compare_prefix: Some((
|
|
||||||
prefix_type,
|
|
||||||
NumericalQuery { condition, value },
|
|
||||||
)),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
return Err(QueryError("Missing argument for search prefix".into()));
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
return Err(QueryError("Missing argument for search prefix".into()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if inside_quotation {
|
} else if inside_quotation {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user