From 6ee9030e372ab1deb0f889d88eb0c9344e67a463 Mon Sep 17 00:00:00 2001 From: jules Date: Mon, 5 Feb 2018 11:12:15 +0000 Subject: [PATCH] Fixed an edge-case in String::compareNatural --- modules/juce_core/text/juce_String.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/modules/juce_core/text/juce_String.cpp b/modules/juce_core/text/juce_String.cpp index 2a95da4daf..5f0c0005a8 100644 --- a/modules/juce_core/text/juce_String.cpp +++ b/modules/juce_core/text/juce_String.cpp @@ -681,7 +681,12 @@ static int naturalStringCompare (String::CharPointerType s1, String::CharPointer const bool hasSpace2 = s2.isWhitespace(); if ((! firstLoop) && (hasSpace1 ^ hasSpace2)) + { + if (s1.isEmpty()) return -1; + if (s2.isEmpty()) return 1; + return hasSpace2 ? 1 : -1; + } firstLoop = false; @@ -690,8 +695,8 @@ static int naturalStringCompare (String::CharPointerType s1, String::CharPointer if (s1.isDigit() && s2.isDigit()) { - const int result = (*s1 == '0' || *s2 == '0') ? stringCompareLeft (s1, s2) - : stringCompareRight (s1, s2); + auto result = (*s1 == '0' || *s2 == '0') ? stringCompareLeft (s1, s2) + : stringCompareRight (s1, s2); if (result != 0) return result; @@ -748,8 +753,8 @@ void String::appendCharPointer (const CharPointerType startOfTextToAppend, { jassert (startOfTextToAppend.getAddress() != nullptr && endOfTextToAppend.getAddress() != nullptr); - const int extraBytesNeeded = getAddressDifference (endOfTextToAppend.getAddress(), - startOfTextToAppend.getAddress()); + auto extraBytesNeeded = getAddressDifference (endOfTextToAppend.getAddress(), + startOfTextToAppend.getAddress()); jassert (extraBytesNeeded >= 0); if (extraBytesNeeded > 0)