Skip to content

Commit 81c80de

Browse files
Update heuristics for accessor section from XML docs #224
1 parent 1022daa commit 81c80de

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed
Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
1+
using System.Text.RegularExpressions;
2+
13
namespace Sundstrom.CheckedExceptions;
24

35
public static class HeuristicRules
46
{
5-
public static bool IsForGetter(string name) => name is not null &&
6-
(name.Contains(" get ") ||
7-
name.Contains(" gets ") ||
8-
name.Contains(" getting ") ||
9-
name.Contains(" retrieved "));
10-
11-
public static bool IsForSetter(string name) => name is not null && (
12-
name.Contains(" set ") ||
13-
name.Contains(" sets ") ||
14-
name.Contains(" setting "));
7+
private static readonly Regex GetterRegex = new(@"\b(gets?|retriev(es|ing|ed)|returns?|provides?)\b",
8+
RegexOptions.IgnoreCase | RegexOptions.Compiled);
9+
10+
private static readonly Regex SetterRegex = new(@"\b(sets?|assigns?|specif(y|ies)|updat(es|ing)|allow(s|ed) setting)\b",
11+
RegexOptions.IgnoreCase | RegexOptions.Compiled);
12+
13+
public static bool IsForGetter(string text) =>
14+
!string.IsNullOrWhiteSpace(text) && GetterRegex.IsMatch(text);
15+
16+
public static bool IsForSetter(string text) =>
17+
!string.IsNullOrWhiteSpace(text) && SetterRegex.IsMatch(text);
18+
public static bool IsForBoth(string text) =>
19+
IsForGetter(text) && IsForSetter(text);
1520
}

0 commit comments

Comments
 (0)