-
Notifications
You must be signed in to change notification settings - Fork 394
Expand file tree
/
Copy pathIssueTracker.cs
More file actions
83 lines (72 loc) · 2.2 KB
/
IssueTracker.cs
File metadata and controls
83 lines (72 loc) · 2.2 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
using System.Text.RegularExpressions;
using CommunityToolkit.Mvvm.ComponentModel;
namespace SourceGit.Models
{
public class IssueTracker : ObservableObject
{
public bool IsShared
{
get => _isShared;
set => SetProperty(ref _isShared, value);
}
public string Name
{
get => _name;
set => SetProperty(ref _name, value);
}
public string RegexString
{
get => _regexString;
set
{
if (SetProperty(ref _regexString, value))
{
try
{
_regex = new Regex(_regexString, RegexOptions.Multiline);
}
catch
{
_regex = null;
}
}
OnPropertyChanged(nameof(IsRegexValid));
}
}
public bool IsRegexValid
{
get => _regex != null;
}
public string URLTemplate
{
get => _urlTemplate;
set => SetProperty(ref _urlTemplate, value);
}
public void Matches(InlineElementCollector outs, string message)
{
if (_regex == null || string.IsNullOrEmpty(_urlTemplate))
return;
var matches = _regex.Matches(message);
foreach (Match match in matches)
{
var start = match.Index;
var len = match.Length;
if (outs.Intersect(start, len) != null)
continue;
var link = _urlTemplate;
for (var j = 1; j < match.Groups.Count; j++)
{
var group = match.Groups[j];
if (group.Success)
link = link.Replace($"${j}", group.Value);
}
outs.Add(new InlineElement(InlineElementType.Link, start, len, link));
}
}
private bool _isShared;
private string _name;
private string _regexString;
private string _urlTemplate;
private Regex _regex = null;
}
}