Better compare of IP strings.

This commit is contained in:
Mitchell Livingston 2006-08-30 21:40:36 +00:00
parent c926d96e32
commit 82a33fa0f6
2 changed files with 12 additions and 18 deletions

View File

@ -162,25 +162,20 @@
if ([self isEqualToString: string]) if ([self isEqualToString: string])
return NSOrderedSame; return NSOrderedSame;
NSEnumerator * selfSections = [[self componentsSeparatedByString: @"."] objectEnumerator], NSArray * selfSections = [self componentsSeparatedByString: @"."],
* newSections = [[string componentsSeparatedByString: @"."] objectEnumerator]; * newSections = [string componentsSeparatedByString: @"."];
if ([selfSections count] != [newSections count])
return [[NSNumber numberWithUnsignedInt: [selfSections count]] compare:
[NSNumber numberWithUnsignedInt: [newSections count]]];
NSEnumerator * selfSectionsEnum = [selfSections objectEnumerator], * newSectionsEnum = [newSections objectEnumerator];
NSString * selfString, * newString;
NSComparisonResult result; NSComparisonResult result;
NSString * selfString = [selfSections nextObject], * newString = [newSections nextObject]; while ((selfString = [selfSectionsEnum nextObject]) && (newString = [newSectionsEnum nextObject]))
while (selfString && newString)
{
if ((result = [selfString compare: newString options: NSNumericSearch]) != NSOrderedSame) if ((result = [selfString compare: newString options: NSNumericSearch]) != NSOrderedSame)
return result; return result;
selfString = [selfSections nextObject];
newString = [newSections nextObject];
}
if (selfString)
return NSOrderedDescending;
else if (newString)
return NSOrderedAscending;
else
return NSOrderedSame; return NSOrderedSame;
} }

View File

@ -106,8 +106,7 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80
if ([barImage size].width < width) if ([barImage size].width < width)
[barImage setSize: NSMakeSize(width * 1.5, BAR_HEIGHT)]; [barImage setSize: NSMakeSize(width * 1.5, BAR_HEIGHT)];
[barImage compositeToPoint: point fromRect: NSMakeRect(0, 0, width, BAR_HEIGHT) [barImage compositeToPoint: point fromRect: NSMakeRect(0, 0, width, BAR_HEIGHT) operation: NSCompositeSourceOver];
operation: NSCompositeSourceOver];
} }
- (void) buildSimpleBar: (float) width point: (NSPoint) point - (void) buildSimpleBar: (float) width point: (NSPoint) point