mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-15 19:27:56 +01:00
[CmdPal][Calc]Also handle normal spaces when the group separator is a non-breaking one (#40328)
## Summary of the Pull Request Fixes space handling for CmdPal's Calculator. Windows uses the no-break space instead of the normal one for locales which use a space for number group separation, however most users don't realize this and expect CmdPal to also handle normal spaces as such, hence this PR. ## PR Checklist - [x] **Closes:** #40273 - [x] **Communication:** I've discussed this with core contributors already. - [ ] **Tests:** Added/updated and all pass - [x] **Localization:** All end-user-facing strings can be localized - [x] **Dev docs:** No need - [x] **New binaries:** None - [x] **Documentation updated:** No need ## Detailed Description of the Pull Request / Additional comments  ## Validation Steps Performed Manually tested calculations with spaces as group separators. Doesn't break with lone standing spaces (e.g. `7 + pi + pi + 7`).
This commit is contained in:
@@ -148,13 +148,16 @@ public class NumberTranslator
|
||||
|
||||
private static Regex GetSplitRegex(CultureInfo culture)
|
||||
{
|
||||
var splitPattern = $"((?:\\d|{Regex.Escape(culture.NumberFormat.NumberDecimalSeparator)}";
|
||||
if (!string.IsNullOrEmpty(culture.NumberFormat.NumberGroupSeparator))
|
||||
var groupSeparator = culture.NumberFormat.NumberGroupSeparator;
|
||||
|
||||
// if the group separator is a no-break space, we also add a normal space to the regex
|
||||
if (groupSeparator == "\u00a0")
|
||||
{
|
||||
splitPattern += $"|{Regex.Escape(culture.NumberFormat.NumberGroupSeparator)}";
|
||||
groupSeparator = "\u0020\u00a0";
|
||||
}
|
||||
|
||||
splitPattern += ")+)";
|
||||
var splitPattern = $"([0-9{Regex.Escape(culture.NumberFormat.NumberDecimalSeparator)}" +
|
||||
$"{Regex.Escape(groupSeparator)}]+)";
|
||||
return new Regex(splitPattern);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user