Issue #401: Add a generic sorting function.

Fixes https://github.com/backdrop/backdrop-issues/issues/401.