/////// File: SortKey.C /////// #include #include #include "SortKey.h" const char *SortKey::key(const char *s) { int i = position; // key position while ( --i > 0 ) // skipping positions { s += strspn(s,delim); s += strcspn(s,delim); } s += strspn(s,delim); return(s); // first char of key } int SortKey::cmp(const char *a, const char *b) { if (position == 0) return( strcmp(a,b)); int ans = keycmp(key(a), key(b)); return(ans); } inline int SortKey::is_del(const char* c) { return(strspn(c,delim) || *c == '\0'); } int SortKey::keycmp(const char *a, const char *b) { for(; *a == *b; a++, b++) { if ( is_del(a) ) return(0); // a equal to b } if ( is_del(a) && is_del(b) ) return(0); if ( is_del(a) ) return(-1); // a less than b else if ( is_del(b) ) return(1); // a greater than b else return(*a - *b); // a not equal to b }