Skip to content

Commit 9be8b71

Browse files
committed
review feedback, CultureInvariant, mild refactor
1 parent edc76fa commit 9be8b71

File tree

2 files changed

+5
-15
lines changed

2 files changed

+5
-15
lines changed

Plugins/Flow.Launcher.Plugin.Calculator/Main.cs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -212,17 +212,8 @@ private static string NormalizeNumber(string numberStr, bool isFunctionPresent,
212212
var parts = processedStr.Split('.');
213213
if (parts.Length > 1)
214214
{
215-
bool isGrouped = true;
216-
for (var i = 1; i < parts.Length; i++)
217-
{
218-
if (parts[i].Length != 3)
219-
{
220-
isGrouped = false;
221-
break;
222-
}
223-
}
224-
225-
if (isGrouped)
215+
var culture = CultureInfo.CurrentCulture;
216+
if (IsValidGrouping(parts, culture.NumberFormat.NumberGroupSizes))
226217
{
227218
processedStr = processedStr.Replace(groupSep, "");
228219
}
@@ -300,7 +291,6 @@ private static bool IsValidGrouping(string[] parts, int[] groupSizes)
300291
return true;
301292
}
302293

303-
304294
private string FormatResult(decimal roundedResult)
305295
{
306296
string decimalSeparator = GetDecimalSeparator();

Plugins/Flow.Launcher.Plugin.Calculator/MainRegexHelper.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ namespace Flow.Launcher.Plugin.Calculator;
44

55
internal static partial class MainRegexHelper
66
{
7-
[GeneratedRegex(@"-?[\d\.,]+", RegexOptions.Compiled)]
7+
[GeneratedRegex(@"-?[\d\.,'\u00A0\u202F]+", RegexOptions.Compiled | RegexOptions.CultureInvariant)]
88
public static partial Regex GetNumberRegex();
99

1010
[GeneratedRegex(@"\B(?=(\d{3})+(?!\d))", RegexOptions.Compiled)]
1111
public static partial Regex GetThousandGroupRegex();
1212

13-
[GeneratedRegex(@"\bpow(\((?:[^()\[\]]|\((?<Depth>)|\)(?<-Depth>)|\[(?<Depth>)|\](?<-Depth>))*(?(Depth)(?!))\))", RegexOptions.Compiled | RegexOptions.RightToLeft | RegexOptions.IgnoreCase)]
13+
[GeneratedRegex(@"\bpow(\((?:[^()\[\]]|\((?<Depth>)|\)(?<-Depth>)|\[(?<Depth>)|\](?<-Depth>))*(?(Depth)(?!))\))", RegexOptions.Compiled | RegexOptions.RightToLeft | RegexOptions.IgnoreCase | RegexOptions.CultureInvariant)]
1414
public static partial Regex GetPowRegex();
1515

16-
[GeneratedRegex(@"\b(sqrt|pow|factorial|abs|sign|ceil|floor|round|exp|log|log2|log10|min|max|lt|eq|gt|sin|cos|tan|arcsin|arccos|arctan|isnan|isint|isprime|isinfty|rand|randi|type|is|as|length|throw|catch|eval|map|clamp|lerp|regex|shuffle)\s*\(", RegexOptions.Compiled | RegexOptions.IgnoreCase)]
16+
[GeneratedRegex(@"\b(sqrt|pow|factorial|abs|sign|ceil|floor|round|exp|log|log2|log10|min|max|lt|eq|gt|sin|cos|tan|arcsin|arccos|arctan|isnan|isint|isprime|isinfty|rand|randi|type|is|as|length|throw|catch|eval|map|clamp|lerp|regex|shuffle)\s*\(", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.CultureInvariant)]
1717
public static partial Regex GetFunctionRegex();
1818
}

0 commit comments

Comments
 (0)