mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 01:15:14 +02:00
Add ends-with operator and fix dataframe operator behavior (#5395)
* add ends-with operator * escape needles in dataframe operator regex patterns
This commit is contained in:
@ -35,6 +35,7 @@ impl Expression {
|
||||
Operator::NotRegexMatch
|
||||
| Operator::RegexMatch
|
||||
| Operator::StartsWith
|
||||
| Operator::EndsWith
|
||||
| Operator::LessThan
|
||||
| Operator::LessThanOrEqual
|
||||
| Operator::GreaterThan
|
||||
|
@ -24,6 +24,7 @@ pub enum Operator {
|
||||
Or,
|
||||
Pow,
|
||||
StartsWith,
|
||||
EndsWith,
|
||||
}
|
||||
|
||||
impl Display for Operator {
|
||||
@ -48,6 +49,7 @@ impl Display for Operator {
|
||||
Operator::LessThanOrEqual => write!(f, "<="),
|
||||
Operator::GreaterThanOrEqual => write!(f, ">="),
|
||||
Operator::StartsWith => write!(f, "starts-with"),
|
||||
Operator::EndsWith => write!(f, "ends-with"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2080,6 +2080,25 @@ impl Value {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn ends_with(&self, op: Span, rhs: &Value, span: Span) -> Result<Value, ShellError> {
|
||||
match (self, rhs) {
|
||||
(Value::String { val: lhs, .. }, Value::String { val: rhs, .. }) => Ok(Value::Bool {
|
||||
val: lhs.ends_with(rhs),
|
||||
span,
|
||||
}),
|
||||
(Value::CustomValue { val: lhs, span }, rhs) => {
|
||||
lhs.operation(*span, Operator::EndsWith, op, rhs)
|
||||
}
|
||||
_ => Err(ShellError::OperatorMismatch {
|
||||
op_span: op,
|
||||
lhs_ty: self.get_type(),
|
||||
lhs_span: self.span()?,
|
||||
rhs_ty: rhs.get_type(),
|
||||
rhs_span: rhs.span()?,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn modulo(&self, op: Span, rhs: &Value, span: Span) -> Result<Value, ShellError> {
|
||||
match (self, rhs) {
|
||||
(Value::Int { val: lhs, .. }, Value::Int { val: rhs, .. }) => {
|
||||
|
Reference in New Issue
Block a user