Skip to content

Commit 3c9977a

Browse files
committed
Added IDescribable to Pattern and implemented it
1 parent bc289cc commit 3c9977a

File tree

3 files changed

+75
-6
lines changed

3 files changed

+75
-6
lines changed

Rubberduck.RegexAssistant/Pattern.cs

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
1+
using Rubberduck.RegexAssistant.i18n;
2+
using System;
63

74
namespace Rubberduck.RegexAssistant
85
{
9-
class Pattern
6+
public class Pattern : IDescribable
107
{
118
IRegularExpression RootExpression;
129
MatcherFlags Flags;
1310

1411
private readonly bool _hasStartAnchor;
1512
private readonly bool _hasEndAnchor;
13+
private readonly string _description;
14+
15+
public string Description
16+
{
17+
get
18+
{
19+
return _description;
20+
}
21+
}
1622

1723
public Pattern(string expression, bool ignoreCase, bool global)
1824
{
@@ -25,8 +31,23 @@ public Pattern(string expression, bool ignoreCase, bool global)
2531
int start = _hasStartAnchor ? 1 : 0;
2632
int end = (_hasEndAnchor ? 1 : 0) + start + 1;
2733
RootExpression = RegularExpression.Parse(expression.Substring(start, expression.Length - end));
34+
_description = AssembleDescription();
2835
}
2936

37+
private string AssembleDescription()
38+
{
39+
string result = string.Empty;
40+
if (_hasStartAnchor)
41+
{
42+
result += Flags.HasFlag(MatcherFlags.Global) ? AssistantResources.PatternDescription_AnchorStart_GlobalEnabled : AssistantResources.PatternDescription_AnchorStart;
43+
}
44+
result += RootExpression.Description;
45+
if (_hasEndAnchor)
46+
{
47+
result += Flags.HasFlag(MatcherFlags.Global) ? AssistantResources.PatternDescription_AnchorEnd_GlobalEnabled : AssistantResources.PatternDescription_AnchorEnd;
48+
}
49+
return result;
50+
}
3051
}
3152

3253
[Flags]

Rubberduck.RegexAssistant/i18n/AssistantResources.Designer.cs

Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Rubberduck.RegexAssistant/i18n/AssistantResources.resx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,18 @@
189189
<data name="ExpressionDescription_AlternativesExpression" xml:space="preserve">
190190
<value>Matches one of the following alternatives {0}.</value>
191191
</data>
192+
<data name="PatternDescription_AnchorEnd" xml:space="preserve">
193+
<value>$ ensures all characters of the string are consumed</value>
194+
</data>
195+
<data name="PatternDescription_AnchorEnd_GlobalEnabled" xml:space="preserve">
196+
<value>$ ensures that the line ended or all characters of the input have been consumed</value>
197+
</data>
198+
<data name="PatternDescription_AnchorStart" xml:space="preserve">
199+
<value>^ ensures we are at the beginning of the string that's to be matched</value>
200+
</data>
201+
<data name="PatternDescription_AnchorStart_GlobalEnabled" xml:space="preserve">
202+
<value>^ ensures that the matcher starts at the beginning of a line</value>
203+
</data>
192204
<data name="Quantifer_Plus" xml:space="preserve">
193205
<value>at least once</value>
194206
</data>

0 commit comments

Comments
 (0)