diff --git a/Plugins/Flow.Launcher.Plugin.Calculator/Main.cs b/Plugins/Flow.Launcher.Plugin.Calculator/Main.cs index 09810b974..282eda7c3 100644 --- a/Plugins/Flow.Launcher.Plugin.Calculator/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.Calculator/Main.cs @@ -12,17 +12,8 @@ namespace Flow.Launcher.Plugin.Calculator { public class Main : IPlugin, IPluginI18n, ISettingProvider { - private static readonly Regex RegValidExpressChar = new Regex( - @"^(" + - @"ceil|floor|exp|pi|e|max|min|det|abs|log|ln|sqrt|" + - @"sin|cos|tan|arcsin|arccos|arctan|" + - @"eigval|eigvec|eig|sum|polar|plot|round|sort|real|zeta|" + - @"bin2dec|hex2dec|oct2dec|" + - @"factorial|sign|isprime|isinfty|" + - @"==|~=|&&|\|\||(?:\<|\>)=?|" + - @"[ei]|[0-9]|0x[\da-fA-F]+|[\+\%\-\*\/\^\., ""]|[\(\)\|\!\[\]]" + - @")+$", RegexOptions.Compiled); - private static readonly Regex RegBrackets = new Regex(@"[\(\)\[\]]", RegexOptions.Compiled); + private static readonly Regex RegValidExpressChar = MainRegexHelper.GetRegValidExpressChar(); + private static readonly Regex RegBrackets = MainRegexHelper.GetRegBrackets(); private static Engine MagesEngine; private const string Comma = ","; private const string Dot = "."; @@ -155,7 +146,7 @@ namespace Flow.Launcher.Plugin.Calculator return value.ToString(numberFormatInfo); } - private string GetDecimalSeparator() + private string GetDecimalSeparator() { string systemDecimalSeparator = CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator; return _settings.DecimalSeparator switch diff --git a/Plugins/Flow.Launcher.Plugin.Calculator/MainRegexHelper.cs b/Plugins/Flow.Launcher.Plugin.Calculator/MainRegexHelper.cs new file mode 100644 index 000000000..8ffc547d1 --- /dev/null +++ b/Plugins/Flow.Launcher.Plugin.Calculator/MainRegexHelper.cs @@ -0,0 +1,13 @@ +using System.Text.RegularExpressions; + +namespace Flow.Launcher.Plugin.Calculator; + +internal static partial class MainRegexHelper +{ + + [GeneratedRegex(@"[\(\)\[\]]", RegexOptions.Compiled)] + public static partial Regex GetRegBrackets(); + + [GeneratedRegex(@"^(ceil|floor|exp|pi|e|max|min|det|abs|log|ln|sqrt|sin|cos|tan|arcsin|arccos|arctan|eigval|eigvec|eig|sum|polar|plot|round|sort|real|zeta|bin2dec|hex2dec|oct2dec|factorial|sign|isprime|isinfty|==|~=|&&|\|\||(?:\<|\>)=?|[ei]|[0-9]|0x[\da-fA-F]+|[\+\%\-\*\/\^\., ""]|[\(\)\|\!\[\]])+$", RegexOptions.Compiled)] + public static partial Regex GetRegValidExpressChar(); +}