|
From: Andre R. <and...@us...> - 2004-11-09 08:54:09
|
Update of /cvsroot/frontierkernel/Frontier/Common/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13913 Modified Files: strings.c Log Message: Added compareidentifiers which compares the input strings case-insensitively and returns -1, 0, or +1 as the result. Useful for maintaining the sort order of tables. Index: strings.c =================================================================== RCS file: /cvsroot/frontierkernel/Frontier/Common/source/strings.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** strings.c 28 Oct 2004 17:22:04 -0000 1.4 --- strings.c 9 Nov 2004 08:54:00 -0000 1.5 *************** *** 204,207 **** --- 204,231 ---- #endif + + short compareidentifiers (bigstring bs1, bigstring bs2) { + + /* + 2004-11-09 aradke: cross between comparestrings and equalidentifiers, + useful for sorting identifiers. + + return zero if the two strings (pascal type, with length-byte) are + equal. return -1 if bs1 is less than bs2, or +1 if bs1 is greater than + bs2. the comparison is not case-sensitive. + */ + + register short n = min (stringlength (bs1), stringlength (bs2)) + 1; + register ptrbyte p1 = (ptrbyte) stringbaseaddress (bs1); + register ptrbyte p2 = (ptrbyte) stringbaseaddress (bs2); + + while (--n) + if (getlower (*p1++) != getlower (*p2++)) + return ((getlower (*--p1) < getlower (*--p2)) ? -1 : +1); /*rewind*/ + + return (sgn (stringlength (bs1) - stringlength (bs2))); + } /*compareidentifiers*/ + + boolean stringlessthan (register bigstring bs1, register bigstring bs2) { |