-
-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds startswith/endswith operators (#280)
- Loading branch information
Showing
7 changed files
with
116 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using Fluid.Values; | ||
using System.Threading.Tasks; | ||
|
||
namespace Fluid.Ast.BinaryExpressions | ||
{ | ||
public class EndsWithBinaryExpression : BinaryExpression | ||
{ | ||
public EndsWithBinaryExpression(Expression left, Expression right) : base(left, right) | ||
{ | ||
} | ||
|
||
public override async ValueTask<FluidValue> EvaluateAsync(TemplateContext context) | ||
{ | ||
var leftValue = await Left.EvaluateAsync(context); | ||
var rightValue = await Right.EvaluateAsync(context); | ||
|
||
if (leftValue is ArrayValue) | ||
{ | ||
var first = await leftValue.GetValueAsync("last", context); | ||
return first.Equals(rightValue) | ||
? BooleanValue.True | ||
: BooleanValue.False; | ||
} | ||
else | ||
{ | ||
return leftValue.ToStringValue().EndsWith(rightValue.ToStringValue()) | ||
? BooleanValue.True | ||
: BooleanValue.False; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using Fluid.Values; | ||
using System.Threading.Tasks; | ||
|
||
namespace Fluid.Ast.BinaryExpressions | ||
{ | ||
public class StartsWithBinaryExpression : BinaryExpression | ||
{ | ||
public StartsWithBinaryExpression(Expression left, Expression right) : base(left, right) | ||
{ | ||
} | ||
|
||
public override async ValueTask<FluidValue> EvaluateAsync(TemplateContext context) | ||
{ | ||
var leftValue = await Left.EvaluateAsync(context); | ||
var rightValue = await Right.EvaluateAsync(context); | ||
|
||
if (leftValue is ArrayValue) | ||
{ | ||
var first = await leftValue.GetValueAsync("first", context); | ||
return first.Equals(rightValue) | ||
? BooleanValue.True | ||
: BooleanValue.False; | ||
} | ||
else | ||
{ | ||
return leftValue.ToStringValue().StartsWith(rightValue.ToStringValue()) | ||
? BooleanValue.True | ||
: BooleanValue.False; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters