/** Sort the groups by their name */ static int CDECL GroupNameSorter(const Group * const *a, const Group * const *b) { static const Group *last_group[2] = { NULL, NULL }; static char last_name[2][64] = { "", "" }; if (*a != last_group[0]) { last_group[0] = *a; SetDParam(0, (*a)->index); GetString(last_name[0], STR_GROUP_NAME, lastof(last_name[0])); } if (*b != last_group[1]) { last_group[1] = *b; SetDParam(0, (*b)->index); GetString(last_name[1], STR_GROUP_NAME, lastof(last_name[1])); } int r = strnatcmp(last_name[0], last_name[1]); // Sort by name (natural sorting). if (r == 0) return (*a)->index - (*b)->index; return r; }
int compare2(const void* arg1, const void* arg2) { // int iosort = _tcsicmp(((plsort2_t*)arg1)->str, ((plsort2_t*)arg2)->str);; // if(iosort == 0) {return 0;} /* CString szA(((plsort2_t*)arg1)->str); CString szB(((plsort2_t*)arg2)->str); int iLen = min(szA.GetLength() , szB.GetLength()); int iLast = 0; for(int i = 0; i < iLen; i++){ TCHAR curCharA = szA.GetAt(i) ; BOOL isNumberA = false; if(curCharA >= '0' && curCharA <= '9') isNumberA = true; TCHAR curCharB = szB.GetAt(i) ; BOOL isNumberB = false; if(curCharB >= '0' && curCharB <= '9') isNumberB = true; if(isNumberA || isNumberB){ if(isNumberA && isNumberB){ break; }else{ return iosort; } }else { if( szA.Left(i+1) == szB.Left(i+1)){ iLast = i; } } }*/ return strnatcmp(((plsort2_t*)arg1)->str, ((plsort2_t*)arg2)->str) ; }
/* support function for qsort() */ static int compare(const void* p1, const void* p2) { struct entry* e1 = (struct entry*)p1; struct entry* e2 = (struct entry*)p2; int criteria; if (e1->attr & ATTR_DIRECTORY && e2->attr & ATTR_DIRECTORY) { /* two directories */ criteria = compare_sort_dir; #ifdef HAVE_MULTIVOLUME if (e1->attr & ATTR_VOLUME || e2->attr & ATTR_VOLUME) { /* a volume identifier is involved */ if (e1->attr & ATTR_VOLUME && e2->attr & ATTR_VOLUME) criteria = SORT_ALPHA; /* two volumes: sort alphabetically */ else /* only one is a volume: volume first */ return (e2->attr & ATTR_VOLUME) - (e1->attr & ATTR_VOLUME); } #endif } else if (!(e1->attr & ATTR_DIRECTORY) && !(e2->attr & ATTR_DIRECTORY)) { /* two files */ criteria = global_settings.sort_file; } else /* dir and file, dir goes first */ return (e2->attr & ATTR_DIRECTORY) - (e1->attr & ATTR_DIRECTORY); switch(criteria) { case SORT_TYPE: case SORT_TYPE_REVERSED: { int t1 = e1->attr & FILE_ATTR_MASK; int t2 = e2->attr & FILE_ATTR_MASK; if (!t1) /* unknown type */ t1 = INT_MAX; /* gets a high number, to sort after known */ if (!t2) /* unknown type */ t2 = INT_MAX; /* gets a high number, to sort after known */ if (t1 != t2) /* if different */ return (t1 - t2) * (criteria == SORT_TYPE_REVERSED ? -1 : 1); /* else fall through to alphabetical sorting */ } case SORT_DATE: case SORT_DATE_REVERSED: /* Ignore SORT_TYPE */ if (criteria == SORT_DATE || criteria == SORT_DATE_REVERSED) { if (e1->time_write != e2->time_write) return (e1->time_write - e2->time_write) * (criteria == SORT_DATE_REVERSED ? -1 : 1); /* else fall through to alphabetical sorting */ } case SORT_ALPHA: case SORT_ALPHA_REVERSED: { if (global_settings.sort_case) { if (global_settings.interpret_numbers == SORT_INTERPRET_AS_NUMBER) return strnatcmp(e1->name, e2->name) * (criteria == SORT_ALPHA_REVERSED ? -1 : 1); else return strncmp(e1->name, e2->name, MAX_PATH) * (criteria == SORT_ALPHA_REVERSED ? -1 : 1); } else { if (global_settings.interpret_numbers == SORT_INTERPRET_AS_NUMBER) return strnatcasecmp(e1->name, e2->name) * (criteria == SORT_ALPHA_REVERSED ? -1 : 1); else return strncasecmp(e1->name, e2->name, MAX_PATH) * (criteria == SORT_ALPHA_REVERSED ? -1 : 1); } } } return 0; /* never reached */ }
/* * Natural Order String Comparison - the 'lessThan' helper function */ static bool lamexp_natural_string_sort_helper(const QString &str1, const QString &str2) { return (strnatcmp(QWCHAR(str1), QWCHAR(str2)) < 0); }
static gint string_nat_compare(gconstpointer a, gconstpointer b) { return strnatcmp(((const struct string_elem *)a)->sstr, ((const struct string_elem *)b)->sstr); }
bool CompareStrings::operator()(char* str1, char* str2) // Returns true if t1 is earlier than t2 { return strnatcmp(str1, str2) >= 0; }
/** Sort content by name. */ static int CDECL NameSorter(const ContentInfo * const *a, const ContentInfo * const *b) { return strnatcmp((*a)->name, (*b)->name); // Sort by name (natural sorting). }
/*! */ bool taiNaturalStringCompLess( const TaiLineData & l, const TaiLineData & r ) { return ( strnatcmp( l.filename, r.filename ) < 0 ); }//koniec funkcji taiNaturalStringComp
/* natural = 1 performs a "natural" numeric sort on strings -Hinoserm */ static int array_tree_compare(array_iter *a, array_iter *b, int case_sens, int objname, bool natural) { char pad_char[] = ""; if (a->type != b->type) { if (a->type == PROG_INTEGER && b->type == PROG_FLOAT) { if (fabs (((double) a->data.number - b->data.fnumber) / (double) a->data.number) < DBL_EPSILON) { return 0; } else if (a->data.number > b->data.fnumber) { return 1; } else { return -1; } } else if (a->type == PROG_FLOAT && b->type == PROG_INTEGER) { if (a->data.fnumber == b->data.fnumber) { return 0; } else if (fabs((a->data.fnumber - b->data.number) / a->data.fnumber) < DBL_EPSILON) { return 0; } else if (a->data.fnumber > b->data.number) { return 1; } else { return -1; } } else if (a->type == PROG_OBJECT && b->type == PROG_STRING && objname && valid_obj(a->data.objref)) { char *astr = (char *) NAME(a->data.objref); char *bstr = (b->data.string) ? b->data.string->data : pad_char; if (case_sens) { if (natural) return strnatcmp(astr, bstr); else return strcmp(astr, bstr); } else { if (natural) return strnatcasecmp(astr, bstr); else return string_compare(astr, bstr); } } else if (a->type == PROG_STRING && b->type == PROG_OBJECT && objname && valid_obj(b->data.objref)) { char *astr = (a->data.string) ? a->data.string->data : pad_char; char *bstr = (char *) NAME(b->data.objref); if (case_sens) { if (natural) return strnatcmp(astr, bstr); else return strcmp(astr, bstr); } else { if (natural) return strnatcasecmp(astr, bstr); else return string_compare(astr, bstr); } } return (a->type - b->type); } /* Indexes are of same type if we reached here. */ if (a->type == PROG_OBJECT && objname && valid_obj(a->data.objref) && valid_obj(b->data.objref)) { char *astr = (char *) NAME(a->data.objref); char *bstr = (char *) NAME(b->data.objref); if (case_sens) { if (natural) return strnatcmp(astr, bstr); else return strcmp(astr, bstr); } else { if (natural) return strnatcasecmp(astr, bstr); else return string_compare(astr, bstr); } } if (a->type == PROG_OBJECT) { if (a->data.objref > b->data.objref) return 1; else if (a->data.objref < b->data.objref) return -1; else return 0; } if (a->type == PROG_FLOAT) { if (a->data.fnumber == b->data.fnumber) { return 0; } else if (fabs((a->data.fnumber - b->data.fnumber) / a->data.fnumber) < DBL_EPSILON) { return 0; } else if (a->data.fnumber > b->data.fnumber) { return 1; } else { return -1; } } else if (a->type == PROG_STRING) { char pad_char[] = ""; char *astr = (a->data.string) ? a->data.string->data : pad_char; char *bstr = (b->data.string) ? b->data.string->data : pad_char; if (case_sens) { if (natural) return strnatcmp(astr, bstr); else return strcmp(astr, bstr); } else { if (natural) return strnatcasecmp(astr, bstr); else return string_compare(astr, bstr); } } else if (a->type == PROG_ARRAY) { /* Sort arrays by memory address. */ /* This is a bug, really. */ /* in a perfect world, we'd compare the array elements recursively. */ return (a->data.array - b->data.array); } else if (a->type == PROG_LOCK) { /* Sort locks by memory address. */ /* This is a bug, really. */ /* in a perfect world, we'd compare the locks by element. */ char *la; char *lb; int retval = 0; la = (char *) unparse_boolexp((dbref) 1, a->data.lock, 0); la = string_dup(la); lb = (char *) unparse_boolexp((dbref) 1, b->data.lock, 0); retval = strcmp(la, lb); free(la); return retval; } else if (a->type == PROG_ADD) { int result = (a->data.addr->progref - b->data.addr->progref); if (result) { return result; } return (a->data.addr->data - b->data.addr->data); } else { return (a->data.number - b->data.number); } }