// // BPUtil.m // Attempt2Recover // // Created by Bea on 23/05/05. // Copyright 2005 __MyCompanyName__. All rights reserved. // #import "BPUtil.h" @implementation BPUtil + (BOOL)point:(NSPoint)point overRect:(NSRect)rect { if (point.x < rect.origin.x || point.x > rect.origin.x + rect.size.width) return NO; if (point.y < rect.origin.y || point.y > rect.origin.y + rect.size.height) return NO; return YES; } + (NSArray *)reversedArray:(NSArray *)array { NSMutableArray *reversedArray = [[NSMutableArray alloc] initWithCapacity:[array count]]; NSObject *obj; NSEnumerator *reverseEnum = [array reverseObjectEnumerator]; while (obj = [reverseEnum nextObject]) { [reversedArray addObject:obj]; } [reversedArray autorelease]; return reversedArray; } + (float)minOfA:(float)a b:(float)b { if (a < b) return a; return b; } + (float)maxOfA:(float)a b:(float)b { if (a > b) return a; return b; } + (NSString *)formattedFileSizeForBytes:(int)sizeInBytes { /* gives exact size if (sizeInBytes < 1000) return [NSString stringWithFormat:@"%db", sizeInBytes]; if (sizeInBytes < 1000000) return [NSString stringWithFormat:@"%ld.%02ldKB", sizeInBytes/1000, sizeInBytes%1000]; return [NSString stringWithFormat:@"%ld.%02ldMB", sizeInBytes/1000000, sizeInBytes%1000000]; */ // this version doesn't do decimal point if (sizeInBytes < 1000) return [NSString stringWithFormat:@"%db", sizeInBytes]; if (sizeInBytes < 1000000) return [NSString stringWithFormat:@"%ldKB", sizeInBytes/1000]; return [NSString stringWithFormat:@"%ldMB", sizeInBytes/1000000]; } + (NSRect)padRect:(NSRect)rect amount:(int)padding { rect.origin.x -= padding; rect.origin.y -= padding; rect.size.width += padding * 2; rect.size.height += padding * 2; return rect; } + (NSSize)scaleSize:(NSSize)size toHeight:(float)wantedHeight { float ratio = wantedHeight / size.height; float width = size.width * ratio; return NSMakeSize(width, wantedHeight); } + (NSSize)scaleSize:(NSSize)size toWidth:(float)wantedWidth { float ratio = wantedWidth / size.width; float height = size.height * ratio; return NSMakeSize(wantedWidth, height); } + (BOOL)isAddressString:(NSString *)aString { NSRange foundRange = [aString rangeOfString:@"@"]; return (foundRange.length > 0); // or, foundRange.location != NSNotFound } @end