forked from dotnet/ProjFileTools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtilities.cs
More file actions
84 lines (69 loc) · 2.44 KB
/
Copy pathUtilities.cs
File metadata and controls
84 lines (69 loc) · 2.44 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
74
75
76
77
78
79
80
81
82
83
84
using Microsoft;
namespace ProjectFileTools.MSBuild
{
internal static class Utilities
{
internal static int GetLine(string text, int position)
{
Requires.NotNullOrEmpty(text, nameof(text));
Requires.Range(position > -1 && position < text.Length, nameof(position), "Position must be positive and less than text.Length");
int line = 0;
for (int ind = 0; ind < position; ind++)
{
if (text[ind] == '\n')
{
line++;
}
}
return line;
}
internal static int GetStartOfLine(string text, int position)
{
Requires.NotNullOrEmpty(text, nameof(text));
Requires.Range(position > -1 && position <= text.Length, nameof(position), "Position must be positive and less than or equal to text.Length");
while (position > 0 && text[position - 1] != '\n')
{
position--;
}
return position;
}
internal static bool IsProperty(string text, int position, out string propertyName)
{
Requires.NotNull(text, nameof(text));
Requires.Range(position > -1 && position < text.Length, nameof(position), "Position must be positive and less than text.Length");
propertyName = null;
if (text[position] == ')' && position > 1)
{
position--;
}
int propStart = position;
int propEnd = position + 1;
while (text[propStart] != '(' && propStart > 1)
{
if (!char.IsLetterOrDigit(text[propStart]))
{
return false;
}
propStart--;
}
if (!(text[propStart] == '(' && text[propStart - 1] == '$'))
{
return false;
}
while (propEnd < text.Length - 1 && text[propEnd] != '.' && text[propEnd] != ')')
{
if (!char.IsLetterOrDigit(text[propEnd]))
{
return false;
}
propEnd++;
}
if (!(text[propEnd] == '.' || text[propEnd] == ')'))
{
return false;
}
propertyName = text.Substring(propStart + 1, propEnd - propStart - 1);
return true;
}
}
}