From: <ny...@us...> - 2006-12-29 03:02:59
|
Revision: 223 http://svn.sourceforge.net/pmplib/?rev=223&view=rev Author: nyaochi Date: 2006-12-28 19:02:59 -0800 (Thu, 28 Dec 2006) Log Message: ----------- Skip articles ('a', 'an', 'the') when sorting strings. This is the required specification for the comparison function in AVL trees. Modified Paths: -------------- trunk/pmplib/lib/pmp_iriverplus3/idx.c Modified: trunk/pmplib/lib/pmp_iriverplus3/idx.c =================================================================== --- trunk/pmplib/lib/pmp_iriverplus3/idx.c 2006-12-29 01:59:32 UTC (rev 222) +++ trunk/pmplib/lib/pmp_iriverplus3/idx.c 2006-12-29 03:02:59 UTC (rev 223) @@ -320,12 +320,34 @@ return COMP(*x, *y); } +static const ucs2char_t* skip_prefix(const ucs2char_t* str) +{ + int i = 0; + static const ucs2char_t ucs2cs_a[] = {'a',' ',0}; + static const ucs2char_t ucs2cs_an[] = {'a','n',' ',0}; + static const ucs2char_t ucs2cs_the[] = {'t','h','e',' ',0}; + static const ucs2char_t *prefix[] = { + ucs2cs_a, ucs2cs_an, ucs2cs_the, NULL, + }; + + while (prefix[i]) { + if (ucs2incmp(str, prefix[i], ucs2len(prefix[i])) == 0) { + return str + ucs2len(prefix[i]); + } + ++i; + } + return str; +} + static int avl_comp_ucs2string(avl_t* avl, uint32_t _x, uint32_t _y) { - ucs2char_t* x = (ucs2char_t*)(avl->buffer + _x); - ucs2char_t* y = (ucs2char_t*)(avl->buffer + _y); ucs2char_t a, b; + const ucs2char_t* x = (const ucs2char_t*)(avl->buffer + _x); + const ucs2char_t* y = (const ucs2char_t*)(avl->buffer + _y); + x = skip_prefix(x); + y = skip_prefix(y); + do { a = ucs2upper(*x); b = ucs2upper(*y); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |