Skip to content

Commit 07ee470

Browse files
add
1 parent 8fecca1 commit 07ee470

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using JetBrains.Annotations;
2+
using SER.Code.ArgumentSystem.Arguments;
3+
using SER.Code.ArgumentSystem.BaseArguments;
4+
using SER.Code.Helpers.Extensions;
5+
using SER.Code.MethodSystem.BaseMethods.Synchronous;
6+
using SER.Code.MethodSystem.MethodDescriptors;
7+
using SER.Code.ValueSystem;
8+
9+
namespace SER.Code.MethodSystem.Methods.TextMethods;
10+
11+
[UsedImplicitly]
12+
public class SubtextMethod : ReturningMethod<TextValue>
13+
{
14+
public override string Description =>
15+
"Removes certain amount of characters from beginning and end of a text value.";
16+
17+
public override Argument[] ExpectedArguments { get; } =
18+
[
19+
new TextArgument("text"),
20+
new IntArgument("beginning amount", 0)
21+
{
22+
Description = "The amount of characters to remove from the beginning of the text.",
23+
DefaultValue = new(0, null)
24+
},
25+
new IntArgument("end amount", 0)
26+
{
27+
Description = "The amount of characters to remove from the end of the text.",
28+
}
29+
];
30+
31+
public override void Execute()
32+
{
33+
var text = Args.GetText("text");
34+
var beginning = Args.GetInt("beginning amount");
35+
var end = Args.GetInt("end amount");
36+
37+
try
38+
{
39+
ReturnValue = text[beginning..^end].ToDynamicTextValue(Script);
40+
}
41+
catch (ArgumentOutOfRangeException)
42+
{
43+
ReturnValue = new StaticTextValue(string.Empty);
44+
}
45+
}
46+
}

0 commit comments

Comments
 (0)