Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
Concat.cs
1using System.Text;
5
7{
12 {
21 : base(new ScriptNode[] { Vector }, new ArgumentType[] { ArgumentType.Vector }, Start, Length, Expression)
22 {
23 }
24
33 public Concat(ScriptNode Vector, ScriptNode Delimiter, int Start, int Length, Expression Expression)
34 : base(new ScriptNode[] { Vector, Delimiter }, new ArgumentType[] { ArgumentType.Vector, ArgumentType.Scalar }, Start, Length, Expression)
35 {
36 }
37
41 public override string FunctionName => nameof(Concat);
42
46 public override string[] DefaultArgumentNames => new string[] { "Vector", "Delimiter" };
47
55 {
56 if (!(Arguments[0] is IVector Vector))
57 return Arguments[0];
58
59 string Delimiter = Arguments.Length > 1 ? Arguments[1].AssociatedObjectValue?.ToString() : null;
60
61 StringBuilder Result = new StringBuilder();
62 bool First = true;
63
64 foreach (IElement Item in Vector.VectorElements)
65 {
66 if (!(Item.AssociatedObjectValue is string s))
67 s = Item.AssociatedObjectValue?.ToString() ?? string.Empty;
68
69 if (First)
70 First = false;
71 else if (!(Delimiter is null))
72 Result.Append(Delimiter);
73
74 Result.Append(s);
75 }
76
77 return new StringValue(Result.ToString());
78 }
79 }
80}
Class managing a script expression.
Definition: Expression.cs:39
Concatenates the elements of a vector, optionally delimiting the elements with a Delimiter.
Definition: Concat.cs:12
Concat(ScriptNode Vector, int Start, int Length, Expression Expression)
Concatenates the elements of a vector, optionally delimiting the elements with a Delimiter.
Definition: Concat.cs:20
override string FunctionName
Name of the function
Definition: Concat.cs:41
override string[] DefaultArgumentNames
Default Argument names
Definition: Concat.cs:46
Concat(ScriptNode Vector, ScriptNode Delimiter, int Start, int Length, Expression Expression)
Concatenates the elements of a vector, optionally delimiting the elements with a Delimiter.
Definition: Concat.cs:33
override IElement Evaluate(IElement[] Arguments, Variables Variables)
Evaluates the function.
Definition: Concat.cs:54
Base class for multivariate funcions.
ScriptNode[] Arguments
Function arguments.
Base class for all nodes in a parsed script tree.
Definition: ScriptNode.cs:69
override string ToString()
Definition: ScriptNode.cs:359
Expression Expression
Expression of which the node is a part.
Definition: ScriptNode.cs:177
int Start
Start position in script expression.
Definition: ScriptNode.cs:92
Collection of variables.
Definition: Variables.cs:25
Basic interface for all types of elements.
Definition: IElement.cs:20
object AssociatedObjectValue
Associated object value.
Definition: IElement.cs:33
Basic interface for vectors.
Definition: IVector.cs:9
ArgumentType
Type of parameter used in a function definition or a lambda definition.
Definition: IFunction.cs:9