mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
expr: short-circuit evaluation for |
This commit is contained in:
@@ -155,8 +155,24 @@ impl AstNode {
|
||||
}
|
||||
}
|
||||
pub fn operand_values(&self) -> Result<Vec<String>, String> {
|
||||
if let Self::Node { operands, .. } = self {
|
||||
if let Self::Node {
|
||||
operands, op_type, ..
|
||||
} = self
|
||||
{
|
||||
let mut out = Vec::with_capacity(operands.len());
|
||||
let mut operands = operands.iter();
|
||||
|
||||
if op_type == "|" {
|
||||
if let Some(value) = operands.next() {
|
||||
let value = value.evaluate()?;
|
||||
out.push(value.clone());
|
||||
if value_as_bool(&value) {
|
||||
out.push(String::from("dummy"));
|
||||
return Ok(out);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for operand in operands {
|
||||
let value = operand.evaluate()?;
|
||||
out.push(value);
|
||||
|
||||
Reference in New Issue
Block a user