Fix 'change texture pack' sort order being wrong, make string compare case insensitive

This commit is contained in:
UnknownShadow200 2018-05-16 20:06:32 +10:00
parent 217065e21c
commit 42373d64d7
2 changed files with 9 additions and 13 deletions

View File

@ -388,12 +388,12 @@ void ListScreen_QuickSort(Int32 left, Int32 right) {
UInt32* keys = buffer->FlagsBuffer; UInt32 key;
while (left < right) {
Int32 i = left, j = right;
Int32 pivot = (i + j) / 2;
String strI, strJ, pivot = StringsBuffer_UNSAFE_Get(buffer, (i + j) / 2);
/* partition the list */
while (i <= j) {
while (StringsBuffer_Compare(buffer, pivot, i) > 0) i++;
while (StringsBuffer_Compare(buffer, pivot, j) < 0) j--;
while ((strI = StringsBuffer_UNSAFE_Get(buffer, i), String_Compare(&pivot, &strI)) > 0) i++;
while ((strJ = StringsBuffer_UNSAFE_Get(buffer, j), String_Compare(&pivot, &strJ)) < 0) j--;
QuickSort_Swap_Maybe();
}
/* recurse into the smaller subset */

View File

@ -411,13 +411,15 @@ Int32 String_Compare(STRING_PURE String* a, STRING_PURE String* b) {
Int32 i;
for (i = 0; i < minLen; i++) {
if (a->buffer[i] == b->buffer[i]) continue;
return a->buffer[i] > b->buffer[i] ? 1 : -1;
UInt8 aCur = a->buffer[i]; Char_MakeLower(aCur);
UInt8 bCur = b->buffer[i]; Char_MakeLower(bCur);
if (aCur == bCur) continue;
return (Int32)aCur - (Int32)bCur;
}
/* all chars are equal here - same string, or a substring */
if (a->length == b->length) return 0;
return a->length > b->length ? 1 : -1;
return a->length - b->length;
}
void String_Format1(STRING_TRANSIENT String* str, const UInt8* format, const void* a1) {
@ -781,12 +783,6 @@ void StringsBuffer_Remove(StringsBuffer* buffer, UInt32 index) {
buffer->UsedElems -= len;
}
Int32 StringsBuffer_Compare(StringsBuffer* buffer, UInt32 idxA, UInt32 idxB) {
String strA = StringsBuffer_UNSAFE_Get(buffer, idxA);
String strB = StringsBuffer_UNSAFE_Get(buffer, idxB);
return String_Compare(&strA, &strB);
}
bool WordWrap_IsWrapper(UInt8 c) {
return c == NULL || c == ' ' || c == '-' || c == '>' || c == '<' || c == '/' || c == '\\';