Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ConcatEvaluator.cs
1using System.Text;
5
7{
12 {
13 private readonly string delimiter;
14 private readonly bool hasDelimiter;
15 private StringBuilder sb = null;
16
22 : base(Node.Arguments[0])
23 {
24 if (Node.Arguments.Length == 2 && Node.Arguments[1] is ConstantElement C)
25 {
26 this.delimiter = ScriptNode.ToString(C.Constant);
27 this.hasDelimiter = !string.IsNullOrEmpty(this.delimiter);
28 }
29 else
30 {
31 this.delimiter = null;
32 this.hasDelimiter = false;
33 }
34 }
35
39 public override void RestartEvaluator()
40 {
41 this.sb = null;
42 }
43
48 public override void AggregateElement(IElement Element)
49 {
50 if (this.sb is null)
51 this.sb = new StringBuilder();
52 else if (this.hasDelimiter)
53 this.sb.Append(this.delimiter);
54
55 this.sb.Append(ScriptNode.ToString(Element));
56 }
57
61 public override IElement GetAggregatedResult()
62 {
63 return new StringValue(this.sb?.ToString() ?? string.Empty);
64 }
65 }
66}
Base class for all types of elements.
Definition: Element.cs:14
Concat(v[,Delimiter]) iterative evaluator
ConcatEvaluator(Concat Node)
Concat(v[,Delimiter]) iterative evaluator
override void RestartEvaluator()
Restarts the evaluator.
override void AggregateElement(IElement Element)
Aggregates one new element.
override IElement GetAggregatedResult()
Gets the aggregated result.
Concatenates the elements of a vector, optionally delimiting the elements with a Delimiter.
Definition: Concat.cs:12
Represents a constant element value.
Base class for all nodes in a parsed script tree.
Definition: ScriptNode.cs:69
int Length
Length of expression covered by node.
Definition: ScriptNode.cs:101
override string ToString()
Definition: ScriptNode.cs:359
An interative evaluator of a function or operation defined by a single ScriptNode.
ScriptNode Node
Node being iteratively evaluated.
Basic interface for all types of elements.
Definition: IElement.cs:21