Updating ITFoundation to include updates spurred by Haven development.
[ITFoundation.git] / ITCategory-NSString.m
1 #import "ITCategory-NSString.h"
2 #import "ITCategory-NSData.h"
3
4 @implementation NSString (ITFoundationCategory)
5
6 + (id)stringWithFourCharCode:(unsigned long)fourCharCode {
7         return [[[self alloc] initWithFourCharCode:fourCharCode] autorelease];
8 }
9
10 - (id)initWithFourCharCode:(unsigned long)fourCharCode {
11         return [self initWithString:(NSString *)UTCreateStringForOSType(fourCharCode)];
12         //return [self initWithFormat:@"%.4s", &fourCharCode];
13 }
14
15 - (unsigned long)fourCharCode {
16         return UTGetOSTypeFromString((CFStringRef)self);
17         
18         //Die nasty bitshifting
19         /*const unsigned char *c_s = [self UTF8String];
20         unsigned long tmp = *c_s++;
21         tmp <<= 8;
22         tmp |= *c_s++;
23         tmp <<= 8;
24         tmp |= *c_s++;
25         tmp <<= 8;
26         return tmp |= *c_s++;*/
27 }
28
29 - (NSData *)MD5 {
30         return [[self dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:NO] MD5];
31 }
32
33 - (NSData *)SHA1 {
34         return [[self dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:NO] SHA1];
35 }
36
37 @end