StephenCleary / Comparers

The last comparison library you'll ever need!
MIT License
427 stars 33 forks source link

Natural string comparer #38

Open StephenCleary opened 2 years ago

StephenCleary commented 2 years ago

It may be better (although possibly less efficient) to split up the current situation more:

  1. Define a splitter that parses a string into (ReadOnlyMemory<char>, IsNumeric) splits.
  2. For sequences of the splits, define a comparer.
  3. The provided implementation of this comparer would be a composite comparer: one for numeric splits and one for non-numeric splits.

This would allow several extension points not currently possible with the current PR:

  1. By providing a custom splitter and a custom numeric split comparer, decimals and/or negative numbers could be supported.
  2. By providing a custom non-numeric split comparer, any kind of (sub)string comparer logic could be supported (currently, we are limited to StringComparison). E.g., handling spaces differently.
  3. By providing a custom composite comparer, the user can change the ordering when a numeric split is compared with a non-numeric split.