Skip to content

Commit

Permalink
Merge pull request #51 from kyberias/master
Browse files Browse the repository at this point in the history
Support parsing of rationals in format '1 2/5'.
  • Loading branch information
tompazourek authored Mar 27, 2023
2 parents d694236 + dd719f9 commit 6a98674
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Rationals/Parsing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public partial struct Rational
RegexOptions.Compiled | RegexOptions.CultureInvariant);

private static readonly Regex WholeFractionalFormat =
new Regex(@"^\s*(?<Whole>-?\d+)\s*[+]\s*(?<Numerator>-?\d+)/(?<Denominator>-?\d+)\s*$",
new Regex(@"^\s*(?<Whole>-?\d+)(\s*[+]\s*|\s+)(?<Numerator>-?\d+)/(?<Denominator>-?\d+)\s*$",
RegexOptions.Compiled | RegexOptions.CultureInvariant);

private static readonly Regex NaNFormat = new Regex(@"^\s*NaN\s*$",
Expand Down
2 changes: 2 additions & 0 deletions tests/Rationals.Tests/ParsingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ public class ParsingTests
{
[Theory]
[InlineData(@"3/4", true, 3, 4)]
[InlineData(@"1 2/5", true, 7, 5)]
[InlineData(@"1 2/5", true, 7, 5)]
[InlineData(@"3\4", false, 0, 0)]
[InlineData(@"3|4", false, 0, 0)]
[InlineData(@"-25/-2310832109823", true, -25, -2310832109823)]
Expand Down

0 comments on commit 6a98674

Please sign in to comment.