From 82a33fa0f6569f1dfb5e3572cd49033db5a8d76d Mon Sep 17 00:00:00 2001 From: Mitchell Livingston Date: Wed, 30 Aug 2006 21:40:36 +0000 Subject: [PATCH] Better compare of IP strings. --- macosx/StringAdditions.m | 27 +++++++++++---------------- macosx/TorrentCell.m | 3 +-- 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/macosx/StringAdditions.m b/macosx/StringAdditions.m index a6ec45ec6..32fcf97b9 100644 --- a/macosx/StringAdditions.m +++ b/macosx/StringAdditions.m @@ -161,27 +161,22 @@ { if ([self isEqualToString: string]) return NSOrderedSame; - - NSEnumerator * selfSections = [[self componentsSeparatedByString: @"."] objectEnumerator], - * newSections = [[string componentsSeparatedByString: @"."] objectEnumerator]; + NSArray * selfSections = [self componentsSeparatedByString: @"."], + * 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; - NSString * selfString = [selfSections nextObject], * newString = [newSections nextObject]; - while (selfString && newString) - { + while ((selfString = [selfSectionsEnum nextObject]) && (newString = [newSectionsEnum nextObject])) 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; + return NSOrderedSame; } @end diff --git a/macosx/TorrentCell.m b/macosx/TorrentCell.m index c2e244b11..b78171c88 100644 --- a/macosx/TorrentCell.m +++ b/macosx/TorrentCell.m @@ -106,8 +106,7 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80 if ([barImage size].width < width) [barImage setSize: NSMakeSize(width * 1.5, BAR_HEIGHT)]; - [barImage compositeToPoint: point fromRect: NSMakeRect(0, 0, width, BAR_HEIGHT) - operation: NSCompositeSourceOver]; + [barImage compositeToPoint: point fromRect: NSMakeRect(0, 0, width, BAR_HEIGHT) operation: NSCompositeSourceOver]; } - (void) buildSimpleBar: (float) width point: (NSPoint) point