Factor out numeric sorting and handle trailing garbage better
Merge pull request #926 from tzz/tzz/2516-numeric-sort

Factor out numeric sorting and handle trailing garbage better