More simplification

This commit is contained in:
Tyrrrz
2022-12-13 03:24:23 +02:00
parent d0ad3bc45d
commit 3d9ad16117
3 changed files with 43 additions and 29 deletions

View File

@@ -0,0 +1,12 @@
// ReSharper disable CheckNamespace
#if NETSTANDARD2_0
using System.Linq;
using System.Text.RegularExpressions;
internal static class RegexPolyfills
{
public static Match[] ToArray(this MatchCollection matches) =>
matches.Cast<Match>().ToArray();
}
#endif

View File

@@ -7,6 +7,6 @@ internal static class StringPolyfills
str.Length > 0 && str[0] == c;
public static bool EndsWith(this string str, char c) =>
str.Length > 0 && str[str.Length - 1] == c;
str.Length > 0 && str[^1] == c;
}
#endif

View File

@@ -52,33 +52,35 @@ internal partial class StackFrame
private const string NotSpace = @"[^\x20\t]";
// Taken from https://github.com/atifaziz/StackTraceParser
private static readonly Regex Pattern = new(@"
^
" + Space + @"*
\w+ " + Space + @"+
(?<frame>
(?<type> " + NotSpace + @"+ ) \.
(?<method> " + NotSpace + @"+? ) " + Space + @"*
(?<params> \( ( " + Space + @"* \)
| (?<pt> .+?) " + Space + @"+ (?<pn> .+?)
(, " + Space + @"* (?<pt> .+?) " + Space + @"+ (?<pn> .+?) )* \) ) )
( " + Space + @"+
( # Microsoft .NET stack traces
\w+ " + Space + @"+
(?<file> ( [a-z] \: # Windows rooted path starting with a drive letter
| / ) # *nix rooted path starting with a forward-slash
.+? )
\: \w+ " + Space + @"+
(?<line> [0-9]+ ) \p{P}?
| # Mono stack traces
\[0x[0-9a-f]+\] " + Space + @"+ \w+ " + Space + @"+
<(?<file> [^>]+ )>
:(?<line> [0-9]+ )
)
)?
)
\s*
$",
private static readonly Regex Pattern = new(
$$"""
^
{{Space}}*
\w+ {{Space}}+
(?<frame>
(?<type> {{NotSpace}}+ ) \.
(?<method> {{NotSpace}}+? ) {{Space}}*
(?<params> \( ( {{Space}}* \)
| (?<pt> .+?) {{Space}}+ (?<pn> .+?)
(, {{Space}}* (?<pt> .+?) {{Space}}+ (?<pn> .+?) )* \) ) )
( {{Space}}+
( # Microsoft .NET stack traces
\w+ {{Space}}+
(?<file> ( [a-z] \: # Windows rooted path starting with a drive letter
| / ) # Unix rooted path starting with a forward-slash
.+? )
\: \w+ {{Space}}+
(?<line> [0-9]+ ) \p{P}?
| # Mono stack traces
\[0x[0-9a-f]+\] {{Space}}+ \w+ {{Space}}+
<(?<file> [^>]+ )>
:(?<line> [0-9]+ )
)
)?
)
\s*
$
""",
RegexOptions.IgnoreCase |
RegexOptions.Multiline |
RegexOptions.ExplicitCapture |
@@ -89,7 +91,7 @@ internal partial class StackFrame
public static IEnumerable<StackFrame> ParseMany(string stackTrace)
{
var matches = Pattern.Matches(stackTrace).Cast<Match>().ToArray();
var matches = Pattern.Matches(stackTrace).ToArray();
if (matches.Length <= 0 || matches.Any(m => !m.Success))
{