-
Notifications
You must be signed in to change notification settings - Fork 0
/
ThemeManager.cs
57 lines (53 loc) · 1.64 KB
/
ThemeManager.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
53
54
55
56
57
using System;
using System.Xml.XPath;
using System.IO;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Linq;
namespace xk3yDVDMenu
{
internal static class ThemeManager
{
public static string Evaluate(string expression)
{
try
{
//Already a number
Int32.Parse(expression);
return expression;
}
catch (Exception)
{
}
try
{
string evaluate = new XPathDocument
(new StringReader("<r/>")).CreateNavigator().Evaluate
(String.Format("number({0})", new
Regex(@"([\+\-\*])")
.Replace(expression, " ${1} ")
.Replace("/", " div ")
.Replace("%", " mod "))).ToString();
Int32.Parse(evaluate);
return evaluate;
}
catch
{
return expression;
}
}
static public string ReplaceVals(string strInput, Dictionary<string, object> Values)
{
var regex = new Regex(@"\{[^\}]*\}");
MatchCollection matches = regex.Matches(strInput);
foreach (Match result in matches)
{
string aggregate = Values.Keys.Aggregate(
result.Value, (current, v) => current.Replace("$" + v, Values[v].ToString())
);
strInput = strInput.Replace(result.Value, ThemeManager.Evaluate(aggregate.Replace("{", "").Replace("}", "")));
}
return strInput;
}
}
}