Skip to content

Compare text naturally in C, Perl, Python, and lua, usable for "natural sort"

Notifications You must be signed in to change notification settings

yasuoka/stralnumcmp

Repository files navigation

stralnumcmp

A comparator for text mixed alphabet and numeric characters in C, Python, Perl, and Lua, which provides "natural sort" like the followings:

9km
10km

or

part9.mp4
part10.mp4

GNU libc has strverscmp(3) in libc(3). strverscmp(3) and this stralnumcmp() are similar, but they differ the way of interpreting strings with leading zeros. strverscmp(3) interprets leading zeros like decimal fractions, more leading zeros is less, but this stralnumcmp() just ignores them. eg., "01" > "002" in strverscmp(3), but "01" < "002" in stralnumcmp(3).

History

  • 2018-03-29 yasuoka
    • On python and lua implementation, comparing a numeric portion and a non numeric port which starts a char less than 0 didn't work properly

About

Compare text naturally in C, Perl, Python, and lua, usable for "natural sort"

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published