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;
|
str.Length > 0 && str[0] == c;
|
||||||
|
|
||||||
public static bool EndsWith(this string str, char 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
|
#endif
|
||||||
@@ -52,33 +52,35 @@ internal partial class StackFrame
|
|||||||
private const string NotSpace = @"[^\x20\t]";
|
private const string NotSpace = @"[^\x20\t]";
|
||||||
|
|
||||||
// Taken from https://github.com/atifaziz/StackTraceParser
|
// Taken from https://github.com/atifaziz/StackTraceParser
|
||||||
private static readonly Regex Pattern = new(@"
|
private static readonly Regex Pattern = new(
|
||||||
|
$$"""
|
||||||
^
|
^
|
||||||
" + Space + @"*
|
{{Space}}*
|
||||||
\w+ " + Space + @"+
|
\w+ {{Space}}+
|
||||||
(?<frame>
|
(?<frame>
|
||||||
(?<type> " + NotSpace + @"+ ) \.
|
(?<type> {{NotSpace}}+ ) \.
|
||||||
(?<method> " + NotSpace + @"+? ) " + Space + @"*
|
(?<method> {{NotSpace}}+? ) {{Space}}*
|
||||||
(?<params> \( ( " + Space + @"* \)
|
(?<params> \( ( {{Space}}* \)
|
||||||
| (?<pt> .+?) " + Space + @"+ (?<pn> .+?)
|
| (?<pt> .+?) {{Space}}+ (?<pn> .+?)
|
||||||
(, " + Space + @"* (?<pt> .+?) " + Space + @"+ (?<pn> .+?) )* \) ) )
|
(, {{Space}}* (?<pt> .+?) {{Space}}+ (?<pn> .+?) )* \) ) )
|
||||||
( " + Space + @"+
|
( {{Space}}+
|
||||||
( # Microsoft .NET stack traces
|
( # Microsoft .NET stack traces
|
||||||
\w+ " + Space + @"+
|
\w+ {{Space}}+
|
||||||
(?<file> ( [a-z] \: # Windows rooted path starting with a drive letter
|
(?<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}?
|
(?<line> [0-9]+ ) \p{P}?
|
||||||
| # Mono stack traces
|
| # Mono stack traces
|
||||||
\[0x[0-9a-f]+\] " + Space + @"+ \w+ " + Space + @"+
|
\[0x[0-9a-f]+\] {{Space}}+ \w+ {{Space}}+
|
||||||
<(?<file> [^>]+ )>
|
<(?<file> [^>]+ )>
|
||||||
:(?<line> [0-9]+ )
|
:(?<line> [0-9]+ )
|
||||||
)
|
)
|
||||||
)?
|
)?
|
||||||
)
|
)
|
||||||
\s*
|
\s*
|
||||||
$",
|
$
|
||||||
|
""",
|
||||||
RegexOptions.IgnoreCase |
|
RegexOptions.IgnoreCase |
|
||||||
RegexOptions.Multiline |
|
RegexOptions.Multiline |
|
||||||
RegexOptions.ExplicitCapture |
|
RegexOptions.ExplicitCapture |
|
||||||
@@ -89,7 +91,7 @@ internal partial class StackFrame
|
|||||||
|
|
||||||
public static IEnumerable<StackFrame> ParseMany(string stackTrace)
|
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))
|
if (matches.Length <= 0 || matches.Any(m => !m.Success))
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user