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:
Mitchell Livingston
2008-06-27 05:40:22 +00:00
parent 313885df00
commit f051a2a789
4 changed files with 11 additions and 24 deletions

View File

@@ -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