From 47833b87858a506df237795426fc9e6fc7bb98c4 Mon Sep 17 00:00:00 2001 From: PesBandi <127593627+PesBandi@users.noreply.github.com> Date: Thu, 10 Jul 2025 13:07:25 +0200 Subject: [PATCH] [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`). --- .../Helper/NumberTranslator.cs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Calc/Helper/NumberTranslator.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Calc/Helper/NumberTranslator.cs index 6930e2fa23..7331c44b40 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Calc/Helper/NumberTranslator.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Calc/Helper/NumberTranslator.cs @@ -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); } }