On Tue, Dec 06, 2005 at 08:37:44AM -0800, Jon A. Cruz wrote:
On Dec 5, 2005, at 11:37 PM, Ted Gould wrote:
If I want to sort a list of strings in alphabetical order, obviously that is dependent on the alphabet being used. How do I find out the order of the alphabet being used? Or, better yet, is their a function to rank two strings based on that alphabet?
Check strcoll()
That and qsort() might make you happy.
(I'd suggest std::sort from <algorithm> instead of C's qsort: it's both more type-safe and, incidentally, faster.)
I'd suggest using g_utf8_collate_key and sorting based on the keys rather than sorting using strcoll (or g_utf8_collate) directly, for two reasons:
(i) The documentation of g_utf8_collate recommends using g_utf8_collate_key when sorting a significant number of strings. (It cites speed reasons: n collation calculations instead of n log n.)
(ii) We can be certain that strcmp (on g_utf8_collate_key values) satisfies the conditions required for sorting (http://www.sgi.com/tech/stl/StrictWeakOrdering.html), whereas I wouldn't be so confident that all implementations of strcoll do: it's very common for custom comparison functions not to satisfy the conditions, in my experience.
pjrm.