Skip to content

Commit 7e5c630

Browse files
committed
Feat: TryGetIndex & TryGetLength
1 parent ff336fd commit 7e5c630

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/CodeOfChaos.Extensions/RegularExpressions/GroupExtensions.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,22 @@ public static bool TryGetValueSpan(this Group group, out ReadOnlySpan<char> valu
2727
value = default;
2828
return false;
2929
}
30+
31+
public static bool TryGetIndex(this Group group, out int index) {
32+
if (group.Success) {
33+
index = group.Index;
34+
return true;
35+
}
36+
index = -1;
37+
return false;
38+
}
39+
40+
public static bool TryGetLength(this Group group, out int length) {
41+
if (group.Success) {
42+
length = group.Length;
43+
return true;
44+
}
45+
length = -1;
46+
return false;
47+
}
3048
}

0 commit comments

Comments
 (0)