mirror of
https://github.com/Tyrrrz/CliFx.git
synced 2025-10-25 15:19:17 +00:00
More simplification
This commit is contained in:
12
CliFx/Utils/Polyfills.Regex.cs
Normal file
12
CliFx/Utils/Polyfills.Regex.cs
Normal 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
|
||||
@@ -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
|
||||
@@ -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(@"
|
||||
private static readonly Regex Pattern = new(
|
||||
$$"""
|
||||
^
|
||||
" + Space + @"*
|
||||
\w+ " + Space + @"+
|
||||
{{Space}}*
|
||||
\w+ {{Space}}+
|
||||
(?<frame>
|
||||
(?<type> " + NotSpace + @"+ ) \.
|
||||
(?<method> " + NotSpace + @"+? ) " + Space + @"*
|
||||
(?<params> \( ( " + Space + @"* \)
|
||||
| (?<pt> .+?) " + Space + @"+ (?<pn> .+?)
|
||||
(, " + Space + @"* (?<pt> .+?) " + Space + @"+ (?<pn> .+?) )* \) ) )
|
||||
( " + Space + @"+
|
||||
(?<type> {{NotSpace}}+ ) \.
|
||||
(?<method> {{NotSpace}}+? ) {{Space}}*
|
||||
(?<params> \( ( {{Space}}* \)
|
||||
| (?<pt> .+?) {{Space}}+ (?<pn> .+?)
|
||||
(, {{Space}}* (?<pt> .+?) {{Space}}+ (?<pn> .+?) )* \) ) )
|
||||
( {{Space}}+
|
||||
( # Microsoft .NET stack traces
|
||||
\w+ " + Space + @"+
|
||||
\w+ {{Space}}+
|
||||
(?<file> ( [a-z] \: # Windows rooted path starting with a drive letter
|
||||
| / ) # *nix rooted path starting with a forward-slash
|
||||
| / ) # Unix rooted path starting with a forward-slash
|
||||
.+? )
|
||||
\: \w+ " + Space + @"+
|
||||
\: \w+ {{Space}}+
|
||||
(?<line> [0-9]+ ) \p{P}?
|
||||
| # Mono stack traces
|
||||
\[0x[0-9a-f]+\] " + Space + @"+ \w+ " + Space + @"+
|
||||
\[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))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user