[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

![image](https://github.com/user-attachments/assets/34e261c1-1d16-42d6-8f82-22aa55a43d7e)
## 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:
PesBandi
2025-07-10 13:07:25 +02:00
committed by GitHub
parent 071f5d7bcc
commit 47833b8785

View File

@@ -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);
}
}