Skip to content

Commit eca5fc5

Browse files
committed
Address feet/inches parser review feedback
1 parent 0b62cb5 commit eca5fc5

2 files changed

Lines changed: 4 additions & 0 deletions

File tree

‎UnitsNet.Tests/CustomCode/LengthTests.FeetInches.cs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public static IEnumerable<object[]> ValidData
4949
["1′1″", 1.08333333, EnglishUs], // Without space
5050
["1 ft 1 in", 1.08333333, EnglishUs],
5151
["1ft 1in", 1.08333333, EnglishUs],
52+
["1 FT 6 IN", 1.5, EnglishUs], // Unit parsing is case-insensitive
5253
["-1'", -1, EnglishUs], // Feet only
5354
["-1′", -1, EnglishUs], // Feet only
5455
["-1,000′", -1000, EnglishUs], // Feet only, with separator
@@ -85,6 +86,7 @@ public void TryParseFeetInches(string str, double expectedFeet, string cultureNa
8586
[InlineData("1'000' 6\"", 1000.5)]
8687
[InlineData("1'000'6\"", 1000.5)]
8788
[InlineData("1'000'000' 2\"", 1000000.16666667)]
89+
[InlineData("1' 1'000\"", 84.33333333)]
8890
[InlineData("-1'000' 6\"", -1000.5)]
8991
public void TryParseFeetInches_WhenGroupSeparatorIsFootAbbreviation_ParsesFeetAndInches(string str, double expectedFeet)
9092
{

‎UnitsNet/CustomCode/Quantities/Length.extra.cs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ private static bool TryParseFeetInchesCombination(string str, IFormatProvider? f
9494
if (isNegative)
9595
str = str.Substring(1).TrimStart();
9696

97+
// Prefer the rightmost foot abbreviation so "1'000' 6\"" treats grouping apostrophes as part of
98+
// the feet value, then keep walking left if that split does not leave valid feet and inches parts.
9799
IReadOnlyList<string> footAbbreviations = UnitAbbreviationsCache.Default.GetUnitAbbreviations(LengthUnit.Foot, formatProvider);
98100
foreach (int splitEndIndex in GetPossibleUnitSplitEndIndexes(str, footAbbreviations))
99101
{

0 commit comments

Comments
 (0)