From 11f5ea5074be16e3b712a05f4484b1c91e3bfa28 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Sun, 14 Sep 2025 12:33:46 +0800 Subject: [PATCH] Improve code quality --- Plugins/Flow.Launcher.Plugin.Calculator/Main.cs | 6 ++---- Plugins/Flow.Launcher.Plugin.Calculator/MainRegexHelper.cs | 4 +++- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.Calculator/Main.cs b/Plugins/Flow.Launcher.Plugin.Calculator/Main.cs index 99f0f8395..0fd32555f 100644 --- a/Plugins/Flow.Launcher.Plugin.Calculator/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.Calculator/Main.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Globalization; -using System.Linq; using System.Runtime.InteropServices; using System.Text.RegularExpressions; using System.Windows.Controls; @@ -16,8 +15,7 @@ namespace Flow.Launcher.Plugin.Calculator private static readonly Regex RegBrackets = MainRegexHelper.GetRegBrackets(); private static readonly Regex ThousandGroupRegex = MainRegexHelper.GetThousandGroupRegex(); private static readonly Regex NumberRegex = MainRegexHelper.GetNumberRegex(); - private static readonly Regex PowRegex = new(@"\bpow(\((?:[^()\[\]]|\((?)|\)(?<-Depth>)|\[(?)|\](?<-Depth>))*(?(Depth)(?!))\))", RegexOptions.Compiled | RegexOptions.RightToLeft); - + private static readonly Regex PowRegex = MainRegexHelper.GetPowRegex(); private static Engine MagesEngine; private const string Comma = ","; @@ -200,7 +198,7 @@ namespace Flow.Launcher.Plugin.Calculator /// Parses a string representation of a number using the system's current culture. /// /// A normalized number string with '.' as the decimal separator for the Mages engine. - private string NormalizeNumber(string numberStr) + private static string NormalizeNumber(string numberStr) { var culture = CultureInfo.CurrentCulture; var groupSep = culture.NumberFormat.NumberGroupSeparator; diff --git a/Plugins/Flow.Launcher.Plugin.Calculator/MainRegexHelper.cs b/Plugins/Flow.Launcher.Plugin.Calculator/MainRegexHelper.cs index 2e0353614..d8c2795dc 100644 --- a/Plugins/Flow.Launcher.Plugin.Calculator/MainRegexHelper.cs +++ b/Plugins/Flow.Launcher.Plugin.Calculator/MainRegexHelper.cs @@ -4,7 +4,6 @@ namespace Flow.Launcher.Plugin.Calculator; internal static partial class MainRegexHelper { - [GeneratedRegex(@"[\(\)\[\]]", RegexOptions.Compiled)] public static partial Regex GetRegBrackets(); @@ -13,4 +12,7 @@ internal static partial class MainRegexHelper [GeneratedRegex(@"\B(?=(\d{3})+(?!\d))", RegexOptions.Compiled)] public static partial Regex GetThousandGroupRegex(); + + [GeneratedRegex(@"\bpow(\((?:[^()\[\]]|\((?)|\)(?<-Depth>)|\[(?)|\](?<-Depth>))*(?(Depth)(?!))\))", RegexOptions.Compiled | RegexOptions.RightToLeft)] + public static partial Regex GetPowRegex(); }