-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathUtils.cs
More file actions
57 lines (51 loc) · 1.22 KB
/
Utils.cs
File metadata and controls
57 lines (51 loc) · 1.22 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
using System;
using System.Globalization;
namespace LiveSplit.MemoryGraph
{
public static class Utils
{
public static float CultureSafeFloatParse(string vstr, float def = 1)
{
//Because C# just uses system's culture which is very problematic for us
if (vstr != null)
{
float value = 0;
if (!float.TryParse(vstr, NumberStyles.Any, CultureInfo.GetCultureInfo("en-US"), out value) &&
!float.TryParse(vstr, NumberStyles.Any, CultureInfo.GetCultureInfo("de-DE"), out value))
{
return def;
}
return value;
}
else
return def;
}
public static bool TryParseEnglishCultureEnforced(string str, out float value)
{
value = 0;
if (!string.IsNullOrEmpty(str))
{
str = str.Replace(',', '.');
return float.TryParse(str, NumberStyles.Any, CultureInfo.GetCultureInfo("en-US"), out value);
}
else
return false;
}
public static bool TryParseHex(string str, out int integer)
{
integer = 0;
if (string.IsNullOrEmpty(str))
{
return false;
}
else
{
if (str.StartsWith("0x", StringComparison.CurrentCultureIgnoreCase))
{
str = str.Substring(2);
}
return int.TryParse(str, NumberStyles.HexNumber, null, out integer);
}
}
}
}