#import "NSColor Additions.h"
#import <OakFoundation/OakFoundation.h>
#import <oak/debug.h>

@implementation NSColor (TMColorAdditions)
+ (NSColor*)colorWithString:(NSString*)aString
{
	if(OakIsEmptyString(aString))
		return nil;

	unsigned int red = 0, green = 0, blue = 0, alpha = 0xFF;
	if(sscanf([aString UTF8String], "#%02x%02x%02x%02x", &red, &green, &blue, &alpha) >= 3)
		return [NSColor colorWithCalibratedRed:red/255.0 green:green/255.0 blue:blue/255.0 alpha:alpha/255.0];

	if([NSColor respondsToSelector:NSSelectorFromString(aString)])
		return [NSColor performSelector:NSSelectorFromString(aString)];

	return nil;
}
@end
