forked from KSP-ModularManagement/ModuleManager
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOperatorParser.cs
More file actions
73 lines (61 loc) · 2.04 KB
/
Copy pathOperatorParser.cs
File metadata and controls
73 lines (61 loc) · 2.04 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
This file is part of Module Manager /L
© 2018-2023 LisiasT
© 2013-2018 Sarbian using System; Blowfish
© 2013 ialdabaoth
Module Manager /L is licensed as follows:
* GPL 3.0 : https://www.gnu.org/licenses/gpl-3.0.txt
Module Manager /L is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
You should have received a copy of the GNU General Public License 3.0
along with Module Manager /L. If not, see <https://www.gnu.org/licenses/>.
*/
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;
}
else if (name.Length == 1 || (name[name.Length - 2] != ' ' && name[name.Length - 2] != '\t'))
{
valueName = name;
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;
}
}
}