Hi Maxim,
I think I found a bug: your package seems to consider `083a` to be less than `9a`.
By the way, I found this because I wrote my on code after I looked at your code and it seemed a bit overcomplicated. For instance, there's really no need to import "unicode/utf8", since lexicographical order (i.e. comparing byte-by-byte in the usual manner) actually just works for UTF-8 and since the bytes used to encode non-ASCII values are all non-ASCII themselves you don't need to work in codepoints to avoid confusing them for digits either.
Anyway, I stole your tests for my package :P and added only a few of my own. One of the tests I added was "does it return the same result as handysort on some randomly-generated strings?", which failed on strings like that.
Also, here are my benchmark results:
BenchmarkStringSort-8 300 5545867 ns/op
BenchmarkUtilStringSort-8 200 8943404 ns/op
BenchmarkHandyStringSort-8 100 20950622 ns/op
BenchmarkStringLess-8 30000000 50.8 ns/op
BenchmarkNaturalLess-8 100000000 17.5 ns/op
As you can see, my method is more than twice as fast as yours (on my machine) at sorting but still about 1.6x slower than a straight-up sort.Strings().
I
did modify these benchmarks slightly (besides adding my own methods) by copying the array before sorting the copy instead of sorting the randomly-generated array directly. This way, if the benchmark wraps around (which it seems they didn't, but still) they won't be sorting an already-sorted array after the first time.
Anyway, my code can be found here:
Import path: "
github.com/fvbommel/util/sortorder"
Code:
https://github.com/fvbommel/util/tree/master/sortorder Docs:
https://godoc.org/github.com/fvbommel/util/sortorderand it passes all of your tests, as well as a (very) few of my own.
Happy coding,
Frits van Bommel