Skip to content

Conversation

angularsen
Copy link
Owner

@angularsen angularsen commented Apr 27, 2020

Motivation

Make it easier to define unit abbreviations in order for Parse() to work for all variations of upper/lowercase in the unit abbreviation.

This was already supported for UnitParser and even though QuantityParser builds on top of UnitParser, it failed due to a regex it computes based on the list of unit abbreviations.

Design

  • Case insensitive parsing should "just work" if it matches exactly one abbreviation
  • If case insensitive parsing matches multiple units, then only an exact match on casing will succeed. Otherwise it already throws UnitNotFoundException in UnitParser.

Examples

  • Volume.Parse("1 L") currently fails, because only lowercase l is defined in JSON. There are no other volume units with the same lowercase abbreviation.

Changes

  • Add ignore case flag to regex in QuantityParser
  • Add tests for happy and sad cases

@angularsen angularsen merged commit a82acf7 into master Apr 27, 2020
@angularsen angularsen deleted the feature/quantity-parse-case-insensitive branch April 27, 2020 21:22
@angularsen
Copy link
Owner Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants