/
OperatorParser.cs
52 lines (43 loc) · 1.27 KB
/
OperatorParser.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System;
namespace ModuleManager
{
public static class OperatorParser
{
public static Operator Parse(string name, out string valueName)
{
if (name == null) throw new ArgumentNullException(nameof(name));
if (name.Length == 0)
{
valueName = string.Empty;
return Operator.Assign;
}
Operator ret;
switch (name[name.Length - 1])
{
case '+':
ret = Operator.Add;
break;
case '-':
ret = Operator.Subtract;
break;
case '*':
ret = Operator.Multiply;
break;
case '/':
ret = Operator.Divide;
break;
case '!':
ret = Operator.Exponentiate;
break;
case '^':
ret = Operator.RegexReplace;
break;
default:
valueName = name;
return Operator.Assign;
}
valueName = name.Substring(0, name.Length - 1).TrimEnd();
return ret;
}
}
}