From 2ea2baa95e015c265ba06d842caf7d0097c3e3d8 Mon Sep 17 00:00:00 2001 From: Hielke Morsink <123mannetje@gmail.com> Date: Sun, 8 May 2016 01:20:18 +0200 Subject: [PATCH] Fix #1038 - Guest List Out Of Order --- src/peep/peep.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/peep/peep.c b/src/peep/peep.c index b6821ad0c4..2109e77563 100644 --- a/src/peep/peep.c +++ b/src/peep/peep.c @@ -10306,11 +10306,29 @@ static void peep_give_real_name(rct_peep *peep) peep->name_string_idx = dx; } -static int peep_name_compare(const utf8 *a, const utf8 *b) +static int peep_name_compare(utf8 const *a, utf8 const *b) { - // TODO be smarter about numbers being on the end - // e.g. Handyman 10 should go after Handyman 4 - return _stricmp(a, b); + for (;; a++, b++) { + int result = tolower(*a) - tolower(*b); + bool both_numeric = *a >= '0' && *a <= '9' && *b >= '0' && *b <= '9'; + if (result != 0 || !*a || both_numeric) { // difference found || end of string + if (both_numeric) { // a and b both start with a number + // Get the numbers in the string at current positions + int na = 0 , nb = 0; + for (; *a >= '0' && *a <= '9'; a++) { na *= 10; na += *a - '0'; } + for (; *b >= '0' && *b <= '9'; b++) { nb *= 10; nb += *b - '0'; } + // In case the numbers are the same + if (na == nb) + continue; + return na - nb; + } + else { + return result; + } + } + } + + assert(false); } /**