-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathStringExtensions.cs
More file actions
72 lines (60 loc) · 2.1 KB
/
Copy pathStringExtensions.cs
File metadata and controls
72 lines (60 loc) · 2.1 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
using System;
using System.Globalization;
namespace Venflow.Score
{
public static class StringExtensions
{
public static string TrimEnd(this string source, string value)
{
if (!source.EndsWith(value))
return source;
return source.Remove(source.LastIndexOf(value));
}
public static double GetNanoSecondTime(this string val)
{
var splittedVal = val.Split(' ', StringSplitOptions.RemoveEmptyEntries);
if (splittedVal.Length != 2)
{
throw new InvalidOperationException($"The format {val} is invalid.");
}
var time = double.Parse(splittedVal[0], NumberStyles.Number, CultureInfo.InvariantCulture.NumberFormat);
switch (splittedVal[1])
{
case "ns":
break;
case "μs":
time *= 1000;
break;
case "ms":
time *= 1000000;
break;
case "s":
time *= 1000000000;
break;
default:
throw new InvalidOperationException($"The time format {splittedVal[1]} is invalid.");
}
return time;
}
public static double GetAllocation(this string val)
{
var splittedVal = val.Split(' ', StringSplitOptions.RemoveEmptyEntries);
if (splittedVal.Length != 2)
{
throw new InvalidOperationException($"The format {val} is invalid.");
}
var size = double.Parse(splittedVal[0], NumberStyles.Number, CultureInfo.InvariantCulture.NumberFormat);
switch (splittedVal[1])
{
case "KB":
break;
case "B":
size /= 1024;
break;
default:
throw new InvalidOperationException($"The size format {splittedVal[1]} is invalid.");
}
return size;
}
}
}