Adding category to NSString that provides the functionality previously
[ITFoundation.git] / ITCategory-NSString.m
1 #import "ITCategory-NSString.h"
2
3 @implementation NSString (ITFoundationCategory)
4
5 + (id)stringWithFourCharCode:(unsigned long)fourCharCode {
6         return [[[self alloc] initWithFourCharCode:fourCharCode] autorelease];
7 }
8
9 - (id)initWithFourCharCode:(unsigned long)fourCharCode {
10         return [self initWithFormat:@"%.4s", &fourCharCode];
11 }
12
13 - (unsigned long)fourCharCode {
14         const unsigned char *c_s = [self UTF8String];
15         unsigned long tmp = *c_s++;
16         tmp <<= 8;
17         tmp |= *c_s++;
18         tmp <<= 8;
19         tmp |= *c_s++;
20         tmp <<= 8;
21         return tmp |= *c_s++;
22 }
23
24 @end