You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Merge pull request #81 from maherkassim/feature/improve-parsing
Improve parsing of unit quantities.
Not all the cases below are implemented. For instance it happily parses unit quantity pairs with no space or delimiters between them. This is left for a future improvement.
---
// Length.Parse() examples
// Multiple quantities are added together
// No invalid text is allowed
// Allowed delimiters between quantities: 1 comma, 1 word "and", N whitespace, or any combination
// Valid strings
1m => 1 meter // single quantity
1m 1" => (1 meter + 1 inch) // valid, but unconventional
1'1" => (1 foot + 1 inch) // special case for feet/inches, allow no space
1dm³ 1L => 2 liters // 2 quantities, separated by space
1m 1m 1m => 3m // 3 quantities, separated by space
1m 1m ... 1m, N times => N m // N quantities, separated by space
1m and 1cm => 1.011m // 2 quantities, separated by "and"-word and whitespace
1m,1cm,1mm => 1.011m // 3 quantities, separated by comma
1m, 1cm, 1mm => 1.011m // 3 quantities, separated by comma
1m, 1cm and 1mm => 1.011m // 3 quantities, separated by a mix of delimiters
1m, 1cm, and 1mm => 1.011m // 3 quantities, separated by a mix of delimiters
1m and 1cm => 1.011m // 3 quantities, separated by a mix of delimiters
1m , and, 1cm => 1.011m // 3 quantities, separated by a mix of delimiters
// Invalid strings, throws exception
1m1cm // 2 quantities, no space
1m monkey 1cm // invalid word
1'' // invalid unit
1mmm // invalid unit
1'1"2" // only 2 quantities of exactly foot and inch is supported without space
1"1' // only 2 quantities of exactly foot and inch is supported without space
0 commit comments