Build regex at compile time

This commit is contained in:
VictoriousRaptor 2025-07-27 18:39:38 +08:00
parent 71e0374640
commit 443d4f7c02
2 changed files with 8 additions and 3 deletions

View file

@ -15,9 +15,8 @@ namespace Flow.Launcher.Plugin.Calculator
{
private static readonly Regex RegValidExpressChar = MainRegexHelper.GetRegValidExpressChar();
private static readonly Regex RegBrackets = MainRegexHelper.GetRegBrackets();
private static readonly Regex ThousandGroupRegex = new Regex(@"\B(?=(\d{3})+(?!\d))", RegexOptions.Compiled);
private static readonly Regex NumberRegex = new Regex(@"[\d\.,]+", RegexOptions.Compiled);
private static readonly Regex ThousandGroupRegex = MainRegexHelper.GetThousandGroupRegex();
private static readonly Regex NumberRegex = MainRegexHelper.GetNumberRegex();
private static Engine MagesEngine;
private const string Comma = ",";

View file

@ -10,4 +10,10 @@ internal static partial class MainRegexHelper
[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();
[GeneratedRegex(@"[\d\.,]+", RegexOptions.Compiled)]
public static partial Regex GetNumberRegex();
[GeneratedRegex(@"\B(?=(\d{3})+(?!\d))", RegexOptions.Compiled)]
public static partial Regex GetThousandGroupRegex();
}