Repository navigation
Let a typed space match a no-break-space separator in Parse [patch] - #176
Open
matt-edmondson wants to merge 1 commit into
Open
matt-edmondson wants to merge 1 commit into
matt-edmondson wants to merge 1 commit into
Conversation
fr-FR groups digits with U+202F, and ru-RU, pl-PL and sv-SE with U+00A0,
but a keyboard types U+0020. Parse compared separators ordinally, so
Parse("1 234,5", fr-FR) threw where decimal, double and int all return
1234.5, and generic INumberBase<T>.Parse code failed only for PreciseNumber.
The group and decimal separators are now matched the way the runtime's
MatchChars does: a U+0020 in the input stands in for a U+00A0 or U+202F in
the separator, and every other character stays ordinal.
Fixes #174
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017vfJW5r5WL5w6Xw9zvRF9a
|
This was referenced Oct 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fixes #174
What changed
fr-FR groups digits with U+202F, and ru-RU, pl-PL, sv-SE and other cultures group with U+00A0. A keyboard types U+0020.
Parsecompared separators ordinally, soPreciseNumber.Parse("1 234,5", fr)threw wheredecimal,doubleandintall return 1234.5. GenericINumberBase<T>.Parsecode therefore failed only forPreciseNumber.A new
StartsWithSeparatorhelper replaces the two ordinalStartsWithchecks, for the decimal separator and the group separator. It matches character by character, the way the runtime'sMatchCharsdoes. A U+0020 in the input may stand in for a U+00A0 or U+202F in the culture's separator. Every other character stays ordinal, so de-CH's U+2019 still requires U+2019, and a culture whose separator is not a no-break space does not start accepting spaces. #152 (currency separators) hasn't landed yet, so there is nothing to extend there. When it does land, its separators should go through the same helper.Tests
New cases in
PreciseNumberParseCultureTests, using hand-builtNumberFormatInfos so they don't depend on ICU:"1 234,5","-1 234 567"and"1 234 567,25"parse under the provider-only overload,NumberStyles.NumberandNumberStyles.Any, for both U+202F and U+00A0 grouping. Each result is checked againstdecimal.Parse.decimalparity..or invariant separator. A U+00A0 does not match a U+202F separator."1 234"still fails underNumberStyles.Float(noAllowThousands).Before the source change, the 4 positive tests fail. With it, all 523 tests pass, and
dotnet build PreciseNumber.slnsucceeds for net7.0–net10.0 with no warnings. Benchmarks were not run. The change only touches the two separator comparisons inParse, adds no allocation, and leaves the hot arithmetic paths alone.Generated by Claude Code