[PTRun][Calculator] Fix CA1874 warning in CalculateEngine

This commit is contained in:
Jeremy Sinclair
2025-07-24 18:52:14 -04:00
parent 62bff082fe
commit e400e9f335

View File

@@ -11,7 +11,7 @@ using Mages.Core;
namespace Microsoft.PowerToys.Run.Plugin.Calculator
{
public class CalculateEngine
public partial class CalculateEngine
{
private readonly Engine _magesEngine = new Engine(new Configuration
{
@@ -45,7 +45,7 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator
// check for division by zero
// We check if the string contains a slash followed by space (optional) and zero. Whereas the zero must not be followed by a dot, comma, 'b', 'o' or 'x' as these indicate a number with decimal digits or a binary/octal/hexadecimal value respectively. The zero must also not be followed by other digits.
if (new Regex("\\/\\s*0(?!(?:[,\\.0-9]|[box]0*[1-9a-f]))", RegexOptions.IgnoreCase).Match(input).Success)
if (DivisionByZeroRegex().IsMatch(input))
{
error = Properties.Resources.wox_plugin_calculator_division_by_zero;
return default;
@@ -124,5 +124,8 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator
return result;
}
[GeneratedRegex("\\/\\s*0(?!(?:[,\\.0-9]|[box]0*[1-9a-f]))", RegexOptions.IgnoreCase, "en-US")]
private static partial Regex DivisionByZeroRegex();
}
}