X-Git-Url: http://git.ithinksw.org/ITFoundation.git/blobdiff_plain/034559d9a2f0b8e607b0365152b9c73732f00e6e..2c8e10b58c81bf1170d3ed8df82b606f0815285f:/ITCategory-NSString.m diff --git a/ITCategory-NSString.m b/ITCategory-NSString.m new file mode 100644 index 0000000..fd036ae --- /dev/null +++ b/ITCategory-NSString.m @@ -0,0 +1,24 @@ +#import "ITCategory-NSString.h" + +@implementation NSString (ITFoundationCategory) + ++ (id)stringWithFourCharCode:(unsigned long)fourCharCode { + return [[[self alloc] initWithFourCharCode:fourCharCode] autorelease]; +} + +- (id)initWithFourCharCode:(unsigned long)fourCharCode { + return [self initWithFormat:@"%.4s", &fourCharCode]; +} + +- (unsigned long)fourCharCode { + const unsigned char *c_s = [self UTF8String]; + unsigned long tmp = *c_s++; + tmp <<= 8; + tmp |= *c_s++; + tmp <<= 8; + tmp |= *c_s++; + tmp <<= 8; + return tmp |= *c_s++; +} + +@end \ No newline at end of file