diff --git a/Foundation/CPString.j b/Foundation/CPString.j index 70e4d74..b749379 100644 --- a/Foundation/CPString.j +++ b/Foundation/CPString.j @@ -422,8 +422,22 @@ var CPStringHashes = new objj_dictionary(); */ - (CPComparisonResult)compare:(CPString)aString options:(int)aMask { + [self compare:aString options:aMask range:CPMakeRange(0,[self length])]; +} + +/* + Compares the receiver to the specified string in the specified range, using options. + @param aString the string with which to compare + @param aMask the options to use for the comparison + @param range the range where to search + @return the result of the comparison +*/ +- (CPComparisonResult)compare:(CPString)aString options:(int)aMask range:(CPRange)range +{ var lhs = self, - rhs = aString; + rhs = aString, + rhsLength = [rhs length], + lhsStart = range.location; if (aMask & CPCaseInsensitiveSearch) { @@ -431,11 +445,15 @@ var CPStringHashes = new objj_dictionary(); rhs = rhs.toLowerCase(); } - if (lhs < rhs) - return CPOrderedAscending; - else if (lhs > rhs) - return CPOrderedDescending; + for(var i = 0; i < range.length && i < rhsLength; i++) + { + if(lhs[lhsStart + i] < rhs[i]) + return CPOrderedAscending; + else if(lhs[lhsStart + i] > rhs[i]) + return CPOrderedDescending; + } + if(range.length == rhsLength) return CPOrderedSame; }