Sort IP addresses correctly.
This commit is contained in:
parent
1043035ce4
commit
cc7b033984
Binary file not shown.
|
@ -39,4 +39,6 @@
|
|||
- (NSAttributedString *) attributedStringFittingInWidth: (float) width
|
||||
attributes: (NSDictionary *) attributes;
|
||||
|
||||
- (NSComparisonResult) compareIP: (NSString *) string;
|
||||
|
||||
@end
|
||||
|
|
|
@ -157,4 +157,31 @@
|
|||
attributes: attributes] autorelease];
|
||||
}
|
||||
|
||||
- (NSComparisonResult) compareIP: (NSString *) string
|
||||
{
|
||||
if ([self isEqualToString: string])
|
||||
return NSOrderedSame;
|
||||
|
||||
NSEnumerator * selfSections = [[self componentsSeparatedByString: @"."] objectEnumerator],
|
||||
* newSections = [[string componentsSeparatedByString: @"."] objectEnumerator];
|
||||
|
||||
NSComparisonResult result;
|
||||
NSString * selfString = [selfSections nextObject], * newString = [newSections nextObject];
|
||||
while (selfString && newString)
|
||||
{
|
||||
if ((result = [selfString compare: newString options: NSNumericSearch]) != NSOrderedSame)
|
||||
return result;
|
||||
|
||||
selfString = [selfSections nextObject];
|
||||
newString = [newSections nextObject];
|
||||
}
|
||||
|
||||
if (selfString)
|
||||
return NSOrderedDescending;
|
||||
else if (newString)
|
||||
return NSOrderedAscending;
|
||||
else
|
||||
return NSOrderedSame;
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
Loading…
Reference in New Issue