mirror of
https://github.com/transmission/transmission.git
synced 2026-04-20 00:40:03 +01:00
comparing with the numeric option works for sorting IP address properly, so let it do the heavy lifting for us
This commit is contained in:
@@ -147,30 +147,18 @@
|
||||
|
||||
- (NSComparisonResult) compareFinder: (NSString *) string
|
||||
{
|
||||
int comparisonOptions = ![NSApp isOnLeopardOrBetter] ? (NSCaseInsensitiveSearch | NSNumericSearch)
|
||||
: (NSCaseInsensitiveSearch | NSNumericSearch| NSWidthInsensitiveSearch | NSForcedOrderingSearch);
|
||||
int comparisonOptions = [NSApp isOnLeopardOrBetter] ? (NSCaseInsensitiveSearch | NSNumericSearch
|
||||
| NSWidthInsensitiveSearch | NSForcedOrderingSearch)
|
||||
: (NSCaseInsensitiveSearch | NSNumericSearch);
|
||||
|
||||
return [self compare: string options: comparisonOptions range: NSMakeRange(0, [self length]) locale: [NSLocale currentLocale]];
|
||||
}
|
||||
|
||||
- (NSComparisonResult) compareIP: (NSString *) string
|
||||
{
|
||||
NSArray * selfSections = [self componentsSeparatedByString: @"."],
|
||||
* newSections = [string componentsSeparatedByString: @"."];
|
||||
|
||||
if ([selfSections count] != [newSections count])
|
||||
return [selfSections count] > [newSections count] ? NSOrderedDescending : NSOrderedAscending;
|
||||
|
||||
NSEnumerator * selfSectionsEnum = [selfSections objectEnumerator], * newSectionsEnum = [newSections objectEnumerator];
|
||||
NSString * selfString, * newString;
|
||||
- (NSComparisonResult) compareNumeric: (NSString *) string
|
||||
{
|
||||
int comparisonOptions = [NSApp isOnLeopardOrBetter] ? (NSNumericSearch | NSForcedOrderingSearch) : NSNumericSearch;
|
||||
NSComparisonResult result;
|
||||
while ((selfString = [selfSectionsEnum nextObject]) && (newString = [newSectionsEnum nextObject]))
|
||||
if ((result = [selfString compare: newString options: comparisonOptions
|
||||
range: NSMakeRange(0, [selfString length]) locale: [NSLocale currentLocale]]) != NSOrderedSame)
|
||||
return result;
|
||||
|
||||
return NSOrderedSame;
|
||||
return [self compare: string options: comparisonOptions range: NSMakeRange(0, [self length]) locale: [NSLocale currentLocale]];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user