-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathSourceRange.cs
80 lines (65 loc) · 2.32 KB
/
SourceRange.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
using SolcNet.DataDescription.Output;
using System;
namespace Meadow.CoverageReport
{
public struct SourceRange
{
public readonly int Offset;
public readonly int OffsetEnd;
public readonly int Length;
public readonly int SourceIndex;
public override string ToString()
{
return $"Index: {SourceIndex}, Offset: {Offset}, Length: {Length}";
}
public bool Contains(SourceRange other)
{
return SourceIndex == other.SourceIndex && Offset <= other.Offset && OffsetEnd >= other.OffsetEnd;
}
public bool Contains(SourceMapEntry other)
{
return SourceIndex == other.Index && Offset <= other.Offset && OffsetEnd >= (other.Offset + other.Length);
}
public override int GetHashCode()
{
return (Offset, Length, SourceIndex).GetHashCode();
}
public bool Equals(SourceRange other)
{
return other.Offset == Offset && other.Length == Length && other.SourceIndex == SourceIndex;
}
public override bool Equals(object obj)
{
return obj is SourceRange other && Equals(other);
}
public SourceRange(string str)
{
var parts = str.AsSpan();
int colonIndex = parts.IndexOf(':');
if (!int.TryParse(parts.Slice(0, colonIndex), out Offset))
{
throw new Exception("Source range parse failed: " + parts.ToString());
}
parts = parts.Slice(colonIndex + 1);
colonIndex = parts.IndexOf(':');
if (!int.TryParse(parts.Slice(0, colonIndex), out Length))
{
throw new Exception("Source range parse failed: " + parts.ToString());
}
parts = parts.Slice(colonIndex + 1);
if (!int.TryParse(parts, out SourceIndex))
{
throw new Exception("Source range parse failed: " + parts.ToString());
}
OffsetEnd = Offset + Length;
}
public static bool operator ==(SourceRange left, SourceRange right)
{
return left.Equals(right);
}
public static bool operator !=(SourceRange left, SourceRange right)
{
return !(left == right);
}
}
}